Welcome to add ArcGIS API for Android QQ Exchange Group: 337469080
First talk about the reasons for writing this article, in the process of discussion in the group, someone mentioned the problem of positioning, just, I have done related work when the relevant things, so summed up, to share out, because I level limited, the bug is unavoidable, but also hope that a higher high man criticized. Nonsense not much to say, directly into the subject.
To locate on the map and display the positioning results in real time, the heuristic logic is very easy: first, receive and resolve GPS or network location information, generally speaking, the location information is WGS84 latitude and longitude, but our map projection is generally not WGS84, so, Location information received to do a coordinate transformation, at the moment, the mode of coordinate conversion has seven or four parameters, but the two parameters of the conversion algorithm and the method is not very convenient, fortunately, ArcGIS support from WGS84 to map projection conversion, Once the conversion is complete, the point will be displayed on the map and the interval refresh can be achieved. Here's how I'm doing it:
1. Define a graphicslayer and add it to map
Graphicslayer Glayergps;
......
Glayergps = new Graphicslayer (); Mapview.addlayer (GLAYERGPS);
2. Define a style that Picturemarkersymbol use to set the position display
Picturemarkersymbol Locationsymbol;
Locationsymbol = New Picturemarkersymbol (This.getresources (). getdrawable (r.drawable.location));
3. Define Locationmanager
Locationmanager locmag;//to position in the map, you need to know the current location, and the location of the current position object is determined,//However, the location object needs to be Locationmanager object to create. The only way to create locationmanager Locmag = (locationmanager) this.getsystemservice (context.location_service);// Get provider List final list<string> providers=locmag.getproviders (true);
4, the circulation provider, obtains the position information according to the provider
Loop provider, obtaining position information for (String provider:providers) {loc = Locmag.getlastknownlocation (provider) based on provider; Locationlistener Locationlistener = new Locationlistener () {/** * position changed when called */public void onlocationchanged (L Ocation location) {lblposition.settext ("Lat:" +string.format ("%.4f", Location.getlatitude ()) + ", Lon:" + String.Format ("%.4f", Location.getlongitude ())); /Refresh Layer Marklocation (location);} Provider invalid when calling public void onproviderdisabled (string arg0) {}//provider is in effect when calling public void onproviderenabled (string arg0 {}//state changes when calling public void Onstatuschanged (String arg0, int arg1, Bundle arg2) {}};locmag.requestlocationupdates (provider , 0, Locationlistener), if (loc!=null) {Double latitude = loc.getlatitude ();d ouble longitude = loc.getlongitude (); Lblposition.settext ("Lat:" +string.format ("%.4f", latitude) + ", Lon:" + String.Format ("%.4f", longitude));// Start Drawing marklocation (loc);}}
5, when the location is not empty, on the map to draw points
/** * Show current position on map * @param location */private void Marklocation (locations) {Glayerpos.removeall ();d ouble locx = Loca Tion.getlongitude ();d ouble locy = Location.getlatitude (); wgspoint = new Point (Locx, locy); MapPoint = (point) geometryengine.project (Wgspoint,spatialreference.create (4326), mapview.getspatialreference ()); /Layer Creation Graphic Graphicpoint = new Graphic (mappoint,locationsymbol); glayerpos.addgraphic (graphicpoint);/* Dash if ( StartPoint = = null) {poly=new Polyline (); startPoint = Mappoint;poly.startpath ((float) startpoint.getx (), (float) Startpoint.gety ()); Graphic graphicline = new Graphic (startpoint,new Simplelinesymbol (color.red,2)); glayergps.addgraphic (graphicline);} */poly.lineto (float) mappoint.getx (), (float) mappoint.gety ()) glayergps.addgraphic (New Graphic (poly,new Simplelinesymbol (color.black,2)));}
6, the Glayerpos display
Glayerpos.setvisible (FALSE);
In this way, the GPS point can be displayed on the map, and can show the path you have taken ...