I. Use Android's auxiliary functions to locate the service
Positioning on mobile devices is almost an essential feature. In Android, devices can be located through GPS, mobile communication networks, and Wi-Fi networks. These positioning functions are all divided into a locationmanager object, we can use the android Positioning Service as follows:
Public class agslocation extends activity {
Mapview map = NULL;
Locationmanager loc = NULL;
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
Map = (mapview) findviewbyid (R. Id. Map );
Loc = (locationmanager) This. getsystemservice (context. location_service );
Loc. requestlocationupdates (locationmanager. gps_provider, 0, 0,
New locationlistener (){
Public void onlocationchanged (location L ){
Point ptlatlon = new point (L. getlongpolling (), L
. Getlatitude ());
Spatialreference sr4326 = spatialreference. Create (4326 );
Point ptmap = (point) geometryengine. Project (ptlatlon, sr4326,
Map. getspatialreference ());
Map. centerat (ptmap );
}
Public void onproviderdisabled (string provider ){
}
Public void onproviderenabled (string provider ){
}
Public void onstatuschanged (string provider, int status,
Bundle extras ){
}
});
}
}
In the code, I chose to use GPS positioning. Note that to use the positioning service (location_service) of the Android system, you must have the corresponding permissions in the android inventory file:
<Manifest...>
<Uses-Permission Android: Name = "android. Permission. access_fine_location"/>
...
</Manifest>
I got the longitude and latitude information from the android positioning service. I also need to project the coordinates to the map. geometryengine is useful here. Now let's use emulator control to simulate a GPS signal sent to the simulator:
This is the approximate location of Beijing. In the code above, we hope that the map can be centered with the coordinates. The actual situation is consistent with the expectation:
Figure 37 simulate GPS Positioning near Beijing
Ii. Appendix online resources:
ArcGIS for Android (Resource Center ):
Http://help.arcgis.com/en/arcgismobile/10.0/apis/android/help/
ArcGIS Android api reference:
Http://help.arcgis.com/en/arcgismobile/10.0/apis/android/api/index.html
Online address of this article:
Http://blog.csdn.net/warrenwyf/category/784554.aspx