location aware gps realtime (android)

6332
14
Jump to solution
07-21-2014 11:46 AM
by Anonymous User
Not applicable

Where do I find the android sdk to allow gps in realtime. Like the ESRI app where the gps move with you.

1 Solution

Accepted Solutions
ShellyGill1
Esri Contributor

If you are building a map with the MapView from the ArcGIS Runtime SDK for Android, then you can use the LocationDisplayManager to set the map to automatically pan in navigation mode. See the LocationDisplayManager class: use the setAutoPan method and set the mode as NAVIGATION, and use the start method to start the auto-panning behaviour. There are differerent auto-pan modes - see the Nearby Sample for an example of using the LOCATION mode in an app.

View solution in original post

14 Replies
Mapperzmap
Deactivated User

The Android SDK


  Location-based applications are now commonplace, but due to the less than optimal accuracy, user movement, the multitude of methods to obtain the location

getting-location.png

String locationProvider = LocationManager.NETWORK_PROVIDER;
// Or, use GPS location data:
// String locationProvider = LocationManager.GPS_PROVIDER;

locationManager.requestLocationUpdates(locationProvider, 0, 0, locationListener);



Location Strategies | Android Developers

0 Kudos
by Anonymous User
Not applicable

Thanks for the advice.

0 Kudos
ShellyGill1
Esri Contributor

If you are building a map with the MapView from the ArcGIS Runtime SDK for Android, then you can use the LocationDisplayManager to set the map to automatically pan in navigation mode. See the LocationDisplayManager class: use the setAutoPan method and set the mode as NAVIGATION, and use the start method to start the auto-panning behaviour. There are differerent auto-pan modes - see the Nearby Sample for an example of using the LOCATION mode in an app.

by Anonymous User
Not applicable

Thanks , i'll give it a shot. Your the Best!

0 Kudos
ThomNgo
Deactivated User

I followed LocationDisplayManager API, and it's still not working. My partial code is below

LocationDisplayManager ldm = mMapView.getLocationDisplayManager();

ldm.setAutoPanMode(AutoPanMode.NAVIGATION

ls.start();

What it does is even it shows the GPS moving, but the map doesn't stay focus (center) on the GPS, hence, the GPS will eventually move off the map. What I did to temporarily fix this is to implement LocationListener, onLocationChanged(Location loc) and have to set the map to zoom at location's longitude/latitude all the time, but performance wise is not very good.

       ldm = mMapView.getLocationDisplayManager();
       ldm.setAutoPanMode(AutoPanMode.LOCATION);
       ldm.setLocationListener(new LocationListener(){

       @Override

       public void onLocationChanged(Location loc) {
            if (loc == null)
                  return;
            if (isMapFocus) {
                  mapOption = new MapOptions(MapType.TOPO, loc.getLatitude(), loc.getLongitude(), 17);
                  mMapView.setMapOptions(mapOption);
            }

          }

      });

Is there any sample that exactly does this?

thanks a lot,

Thom

0 Kudos
ShellyGill1
Esri Contributor

If you're seeing the GPS updates on the map, first thing I would check is that you're not touching the map at all after the auto-pan is set - auto-panning is automatically turned off if the user interacts with the map and changes the extent manually (zooming or panning) or if the extent is changed programmatically - check getAutoPanMode(), and also worth checking that the location updates started correctly, using isStarted().

0 Kudos
ThomNgo
Deactivated User

Thanks Shelly,

I checked isStarted() and it showed "true". Checked GetAutoPanMode(), it showed from NAVIGATION to OFF. The reason it went from NAVIGATION to OFF is because perhaps I zoomed to the GPS location after the map initialized. I have to zoom it because otherwise it only displays the world map from out of space view, which not really helping. Is there a way to setAutoPanMode from OFF back to NAVIGATION? Why autoPanMode not zooming to the GPS location automatically?

Thanks,

Thom

0 Kudos
ShellyGill1
Esri Contributor

Hi Thom,

As far as I know, autoPanMode will pan, but it will not zoom, so perhaps you can set the zoom level you wish to use before you start the navigation? One way to do this automatically might be to set the AutoPanMode to OFF, set the LocationListener, and start() the LocationDisplayManager. Then just in the first call to onLocationChanged, set the zoom level there, and then switch the AutoPanMode to NAVIGATION. I've added some code as an example below.

Also I will make a note that we could add a sample to demonstrate navigation auto-pan mode, along with the initial zoom in, to the SDK.

   mLocationDisplayManager = mMapView.getLocationDisplayManager();

   mLocationDisplayManager.setAutoPanMode(AutoPanMode.OFF);

   mLocationDisplayManager.setLocationListener(new LocationListener() {

     boolean locationChanged = false;

     @Override

     public void onLocationChanged(Location location) {

 

     if (!locationChanged) {

 

       Point currentPt = new Point(location.getLongitude(), location.getLatitude());

       Point currentMapPt = (Point) GeometryEngine.project(currentPt, SpatialReference.create(4326), mMapView.getSpatialReference());

   

       // Use a suitable value for the typical app usage for when no accuracy is available.

       float accuracy = 100;

       if (location.hasAccuracy()) {

         accuracy = location.getAccuracy();

       }

   

       // Convert the accuracy to units of the map, and apply a suitable zoom factor for the app.

       Unit mapUnits = mMapView.getSpatialReference().getUnit();

       double zoomToWidth = 50 * Unit.convertUnits(accuracy, Unit.create(LinearUnit.Code.METER), mapUnits);

       Envelope zoomExtent = new Envelope(currentMapPt, zoomToWidth, zoomToWidth);

     

       // Make sure that the initial zoom is dont WITHOUT animation, or it may interfere with autopan.

       mMapView.setExtent(zoomExtent, 0, false);

 

       // Dont run this again.

     locationChanged = true;

 

     // Now switch to navigation mode.

     mLocationDisplayManager.setAutoPanMode(AutoPanMode.NAVIGATION);

     }

     }

 

     @Override

     public void onProviderDisabled(String provider) {

     }

 

     @Override

     public void onProviderEnabled(String provider) {

     }

 

     @Override

     public void onStatusChanged(String provider, int status, Bundle extras) {

     }

   });

 

   mLocationDisplayManager.start();

ThomNgo
Deactivated User

Thanks Shelly,

It worked. The difference between your code and my code is I used mMapView.zoomTo() to zoom, and it will stop AutoPan (because of animation?), even after I set autoPanMode back to Navigation.

mMapView.setExtent() in your example should do the trick.

thanks,

Thom

0 Kudos