How to get coordinates of an address in android

后端 未结 5 2006
[愿得一人]
[愿得一人] 2021-01-30 04:29

How do i get gps co-ordinates of the location/address entered by user in android ?

5条回答
  •  时光说笑
    2021-01-30 05:11

    You can use Android's Geocoder to do reverse geocoding:

    Geocoder geocoder = new Geocoder(this, Locale.getDefault());
    List
    addresses = geocoder.getFromLocationName(myLocation, 1); Address address = addresses.get(0); double longitude = address.getLongitude(); double latitude = address.getLatitude();

    Also include the following in AndroidManifest.xml:

    
    

    Also note that you need to be using an API which includes a Geocoder implementation. APIs which include this are the Android Google APIs for example. You can use Geocoder.isPresent() to check if an implementation exists for your targeted API.

    Check out the Geocoder documentation for more information.

提交回复
热议问题