ArcGIS API for Android case study 17

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.