How can I find the latitude and longitude from address?

前端 未结 9 1161
礼貌的吻别
礼貌的吻别 2020-11-22 10:27

I want to show the location of an address in Google Maps.

How do I get the latitude and longitude of an address using the Google Maps API?

9条回答
  •  一整个雨季
    2020-11-22 10:53

    Geocoder coder = new Geocoder(this);
            List
    addresses; try { addresses = coder.getFromLocationName(address, 5); if (addresses == null) { } Address location = addresses.get(0); double lat = location.getLatitude(); double lng = location.getLongitude(); Log.i("Lat",""+lat); Log.i("Lng",""+lng); LatLng latLng = new LatLng(lat,lng); MarkerOptions markerOptions = new MarkerOptions(); markerOptions.position(latLng); googleMap.addMarker(markerOptions); googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng,12)); } catch (IOException e) { e.printStackTrace(); }

提交回复
热议问题