Android GPS location, get city name

Source: Internet
Author: User

First, the location city is based on the Map service API.

GPS positioning the city requires two steps:

1, to obtain the user's current location of longitude, latitude.

2. Convert to city name according to latitude and longitude.

You can only use map services when you convert to city name by latitude. I can't do it by myself.

There are two Map service APIs, one is Baidu map, the other is Google map. Baidu Map API calls need to register Baidu account, and apply for App_key, Google Maps API directly call can.

Baidu Map API call Address: http://api.map.baidu.com/geocoder?output=json&location= latitude, longitude &key=app_key

Google Maps Service API call address: http://maps.google.com/maps/api/geocode/json?latlng= latitude, longitude &language=zh-cn&sensor=true

You can set the return data format, JSON, or XML.

* On Android, parsing JSON is simpler than parsing XML.

Baidu Map API Return Data Format Description can be found in the link: http://dev.baidu.com/wiki/mapws/index.php?title=Geocoding

Google Maps API return data format more detailed, specific data format, you can see the output of this link: http://maps.google.com/maps/api/geocode/json?latlng=22.552549,113.951320 &language=zh-cn&sensor=true

How to parse JSON is not covered in this article.

Android GPS location, get city name

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.