Reputation: 332
How to zoom to a country by name in an Android application(google map)? IF I get a coutry name Ireland then the map location to the Ireland
Upvotes: 2
Views: 913
Reputation: 44158
You can use the Geocoder API to fetch the location based on the country name and then animate the map camera to that position:
try {
List<Address> address = new Geocoder(this).getFromLocationName("Ireland", 1);
if (address == null) {
Log.e(TAG, "Not found");
} else {
Address loc = address.get(0);
Log.e(TAG, loc.getLatitude() + " " + loc.getLongitude());
LatLng pos = new LatLng(loc.getLatitude(), loc.getLongitude())
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(pos, 14));
}
} catch (IOException e) {
e.printStackTrace();
}
Upvotes: 0
Reputation: 380
1 Get location by country name
Geocoder geocoder = new Geocoder(<your context>);
List<Address> addresses;
addresses = geocoder.getFromLocationName(<String address>, 1);
if(addresses.size() > 0) {
double latitude= addresses.get(0).getLatitude();
double longitude= addresses.get(0).getLongitude();
}
2 Zoom to current location
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lng), 10));
Upvotes: 2