How do i get gps co-ordinates of the location/address entered by user in android ?
Here is a complete sample
First define a zoom
final CameraUpdate zoom = CameraUpdateFactory.zoomTo(5);
Clear any map markers
mMap.clear();
//Declare a new marker
final MarkerOptions mp = new MarkerOptions();
//declare a EditText to get the user informed address
EditText etEndereco = findViewById(R.id.map_prof_etEnd);
Geocoder geocoder = new Geocoder(map_prof.this);
List addresses = null;
try {
addresses = geocoder.getFromLocationName(etEndereco.getText().toString(), 1);
} catch (IOException e) {
e.printStackTrace();
}
if (addresses.size() > 0) {
double latitude = addresses.get(0).getLatitude();
double longitude = addresses.get(0).getLongitude();
mp.position(new LatLng(latitude, longitude));
Log.e("teste map2", "inserted latitude " + Latitude + ", inserted Longitude " + Longitude);
mp.title("Selected location");
CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng(latitude, longitude));
mMap.clear();
mMap.addMarker(mp);
mMap.moveCamera(center);
mMap.animateCamera(zoom);
}