The Android-based Baidu map enables the input address to return latitude and longitude information, android latitude and longitude

Source: Internet
Author: User

The Android-based Baidu map enables the input address to return latitude and longitude information, android latitude and longitude
1 solution 1

For the solution, refer to the self-published article. For the entered address information, the city name + specific address name are required.

 

If the entered address information is only the specific address name, but not the city name, the latitude and longitude information may not be parsed. There is also a clear deviation between the parsed longitude and latitude and then reverse resolution and the map marked as a landmark. The actual geographic distance of the deviation is about 1 km ..., this is the result of the host's actual machine running detection. It cannot be completely certain whether the situation is like this. Another point is that the application may crash when parsing. The result of my test will be flashed back once. The second time I clicked the application again, the correct parsing result will appear.

 

Finally, let's take a look at the resolved longitude and latitude coordinates. The final number result must be divided by the Sixth Power of 10 (that is, 1e6). Otherwise, an error will be reported when the reverse resolution is to the GEO chart. In addition, if multiple addresses are resolved at the same time in the listener method, the system may continue to crash. Therefore, the following code is for reference only.

 

Implementation Method:

Public GeoPoint getGeoPointBystr (String str) {GeoPoint gpGeoPoint = null; if (str! = Null) {Geocoder gc = new Geocoder (getActivity (), Locale. CHINA); List <Address> addressList = null; try {addressList = gc. getFromLocationName (str, 1); if (! AddressList. isEmpty () {Address address_temp = addressList. get (0); // calculate the Longitude and Latitude double Latitude = address_temp.getLatitude () * 1E6; double longlatitude = address_temp.getlongdistance () * 1E6; System. out. println ("longitude:" + Latitude); System. out. println ("Latitude:" + longpolling); // produce GeoPoint gpGeoPoint = new GeoPoint (int) Latitude, (int) longpolling) ;}} catch (IOException e) {e. printStackTrace () ;}return gpGeoPoint ;}

 

 

Call the preceding method to parse the longitude and latitude:

GeoPoint result = getGeoPointBystr ("Wuhan Central South University for Nationalities"); Double num_latitude = (result. getLatitudeE6 ()/1e6; Double num_long1_= (result. getLongitudeE6 ()/1e6;

 

 

 

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.