Android gets the current position based on known latitude and longitude coordinates

Source: Internet
Author: User

For example: Longitude: 10.123456 Latitude: 20.654321


Get to the actual location according to the above coordinates (do not use Baidu map or the API of the map of Gao de)


The code is as follows:

Put it in latitude and longitude. Public string getaddress (double latitude, double longitude)  {         geocoder geocoder = new geocoder (this,  Locale.getdefault ());        try {             List<Address> addresses =  Geocoder.getfromlocation (latitude,             &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;LONGITUDE,&NBSP;1);             if  (Addresses.size ()  > 0)  {                 Address address =  Addresses.get (0);                 string data = address.tostring ();                 int  Startcity = data.indexof ("1:\" ")  + " 1:\ "". Length ();                 int endcity = data.indexof ("\" ",  startcity);                 string city = data.substring (startcity, endcity);                 int startplace = data.indexof ("feature=")  +  "feature=". Length ();                 int endplace = data.indexof (",",  startPlace);                 string place  = data.substring (Startplace,&nbsP;endplace);                 return city + place ;             }        } catch  (ioexception e)  {             e.printstacktrace ();         }        return  "Get Failed";     }


This article is from the "Mobile Platform Development" blog, make sure to keep this source http://liuxudong1001.blog.51cto.com/10877072/1749869

Android gets the current position based on known latitude and longitude coordinates

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.