Opened the previous things, looked at, a lot of logic from the chaos, to do the modification, the completion of the implementation of the effect is:
Mapactivity source code is as follows:
Package Com.lzugis.map;import Java.io.file;import Java.util.iterator;import android.app.activity;import Android.content.context;import Android.content.intent;import Android.location.gpssatellite;import Android.location.gpsstatus;import Android.location.location;import Android.location.locationlistener;import Android.location.locationmanager;import Android.location.locationprovider;import Android.os.Bundle;import Android.os.environment;import Android.provider.settings;import Android.util.log;import android.view.Gravity; Import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.button;import Android.widget.toast;import Com.esri.android.map.graphicslayer;import Com.esri.android.map.mapview;import Com.esri.android.map.ags.arcgislocaltiledlayer;import Com.esri.android.runtime.arcgisruntime;import Com.esri.core.geometry.geometryengine;import Com.esri.core.geometry.point;import Com.esri.core.geometry.spatialreference;import Com.esri.core.map.graphic;import COM.ESRI.core.symbol.picturemarkersymbol;import Com.lzugis.tool.zoomctrl;public class Mapactivity extends Activity {private Static File datafile;private static string dirname;private static string Filename;private Locationlistener Locationlistener = new Locationlistener () {/** * Position information is triggered when change/public void onlocationchanged (location l ocation) {marklocation (location);} /** * */public void onstatuschanged (String provider, int status, Bundle extras) is called when the state changes {switch (status) { When the GPS status is visible, case LocationProvider.AVAILABLE:showToast ("Current GPS status is visible"); LOG.I ("TAG", "Current GPS status is visible"); Break The GPS status is outside the service area case LocationProvider.OUT_OF_SERVICE:showToast ("Current GPS status is outside the service area status"); LOG.I ("TAG", "Current GPS status is outside the service area status"); Break The GPS status is pause service when case LocationProvider.TEMPORARILY_UNAVAILABLE:showToast ("Current GPS status is paused service status");LOG.I ("TAG", "Current GPS status is suspend service status"); Break }}/** * triggered */public void onproviderenabled (String provider) {Showtoast ("GPS on") when GPS is turned on; Location Location=locmag.getlastknownlocation (provider), marklocation (location);} /** * When GPS is disabled trigger */public void onproviderdisabled (String provider) {Showtoast ("GPS closed");}}; Mapview Mapview; Arcgislocaltiledlayer Local; Zoomctrl Zoomctrl; Graphicslayer Glayergps; Button btnposition; Toast Toast; Locationmanager Locmag; Location Loc; /** called when the activity is first created. */@Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.LAYOUT.MAIN_MAP); Remove Watermark Arcgisruntime.setclientid ("1EFHW78AVLNRUPHM"); To position the location in the map, you need to know the current position, and the location object is determined by the current position,//However, the site object needs to be created with the Locationmanager object. The only way to create locationmanager Locmag = (locationmanager) this.getsystemservice (Context.location_service); Mapview = (Mapview) Findviewbyid (R.ID.MAP); DataFile = Environment.getexternalstoragedirectory (); DirName = This.getresources (). getString (r.string.offline_dir); filename = This.getresources (). GetString ( R.STRING.LOCAL_TPK); String basemap = "file://" +datafile + file.separator +dirname + file.separator + filename; Local = new Arcgislocaltiledlayer (BASEMAP); Mapview.addlayer (local); Zoom in and zoom out Zoomctrl = (Zoomctrl) Findviewbyid (R.id.zoomcontrol); Zoomctrl.setmapview (Mapview); Glayergps = new Graphicslayer (); Mapview.addlayer (GLAYERGPS); btnposition= (Button) Findviewbyid (r.id.btnposition); Btnposition.setonclicklistener (New Onclicklistener () {public void OnClick (View v) {///Determine if GPS is starting properly if (!loc Mag.isproviderenabled (Locationmanager.gps_provider)) {Showtoast ("Please turn on GPS navigation ..."); Return to the open GPS navigation settings interface Intent Intent = new Intent (settings.action_location_source_settings); Startactivityforresult (intent,0); Return } location location= locmag.getlastknownlocation (Locationmanager.gps_provider); Marklocation (location); Locmag.addgpsstatuslistener (listener); Locmag.requestlocationupdates (locationmanager.gps_provider, 0, Locationlistener); } }); }//Status monitor Gpsstatus.listener Listener = new Gpsstatus.listener () {public void ongpsstatuschanged (int even T) {switch (event) {///First position case GPSSTATUS.GPS_EVENT_FIRST_FIX:LOG.I ("t AG "," first position "); Break Satellite status change Case gpsstatus.gps_event_satellite_status:log.i ("TAG", "Satellite state Change"); Gets the current state gpsstatus gpsstatus=locmag.getgpsstatus (NULL); Gets the default maximum value of the number of satellites int maxsatellites = Gpsstatus.getmaxsatellites (); Create an iterator save all satellites Iterator<GpsSatellite> iters = Gpsstatus.getsatellites (). iterator (); int count = 0; while (Iters.hasnext () && count <= maxsatellites) {gpssatellite s = iters.next (); count++; } System.out.println ("Search to:" +count+ "satellites"); Break Locate the Startup case gpsstatus.gps_event_started:log.i ("TAG", "location start"); Break Locate End Case GPSSTATUS.GPS_EVENT_STOPPED:LOG.I ("TAG", "end of position"); Break } }; }; private void Marklocation (location location) {if (location!=null) {log.i ("TAG", "Time:" +location.gettime ()); LOG.I ("TAG", "Longitude:" +location.getlongitude ()); LOG.I ("TAG", "Latitude:" +location.getlatitude ()); LOG.I ("TAG", "Elevation:" +location.getaltitude ()); Double locx = location.getlongitude ();d ouble locy = Location.getlatitude (); ShowPoIntonmap (Locx,locy); }} public void Showpointonmap (double lon,double lat) {//empties the location layer Glayergps.removeall ();//received GPS signal X (LAT), Y (LON) Double Locx = lon;double Locy = lat; Point wgspoint = new Point (Locx, locy); Point mapPoint = (point) geometryengine.project (Wgspoint,spatialreference.create (4326), mapview.getspatialreference ());//creation of the layer//graphic Graphic = new Graphic (mappoint,new simplemarkersymbol (Color.red,18,style. CIRCLE)); Picturemarkersymbol PMS = new Picturemarkersymbol (This.getresources (). getdrawable (r.drawable.location)); Graphic Graphic = new Graphic (MAPPOINT,PMS); glayergps.addgraphic (Graphic);} private void Showtoast (String msg) {if (toast = = null) {toast = Toast.maketext (this, MSG, TOAST.L Ength_short); } else {Toast.settext (msg); Toast.setduration (Toast.length_short); } toast.setgravity (gravity.bottom, 0, 0); Toast.show (); } @Overrideprotected void OnDestroy () {Super.ondeStroy ();} @Overrideprotected void OnPause () {super.onpause (); Mapview.pause ();} @Overrideprotected void Onresume () {super.onresume (); Mapview.unpause ();}}
Arcgis for Android GPS positioning implementation