empeypp

Location Service (GPS)

Discussion created by empeypp on Jan 4, 2012
Latest reply on Jul 27, 2012 by JFA0427
I need to find the user location with the phone's GPS. I know that the LocationService class is used but I'm not sure how. My map works fine but I do not know how to put that little blue circle on the map with the user location. Below is my code:
public class HelloWorld extends Activity {
 MapView map = null;


 /** Called when the activity is first created. */
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  
  // Retrieve the map and initial extent from XML layout
  map = (MapView)findViewById(R.id.map);
  // Add dynamic layer to MapView
  map.addLayer(new ArcGISDynamicMapServiceLayer("" +
    "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"));
  
  //Retrieve the non-configuration instance data that was previously returned. 
  Object init = getLastNonConfigurationInstance();
  if (init != null) {
   map.restoreState((String) init);
   
   
   LocationService ls = map.getLocationService();
   ls.setAccuracyCircleOn(true);
   ls.start();
  } 
 }
 

 protected void onPause() {
  super.onPause();
  map.pause();
 }

 protected void onResume() {
  super.onResume(); 
  map.unpause();
 } 
 
}

Outcomes