How do I search for an address in Google Maps for Android, from the location name?
How do I search for an address in Google Maps for Android, from the location name?
You can use this function:
adderess = c.getString(c.getColumnIndex(SQLiteAdapter.KEY_CONTENT3));
// get address in string for used location for the map
/* get latitude and longitude from the adderress */
Geocoder geoCoder = new Geocoder(this, Locale.getDefault());
try
{
List<Address> addresses = geoCoder.getFromLocationName(adderess, 5);
if (addresses.size() > 0)
{
Double lat = (double) (addresses.get(0).getLatitude());
Double lon = (double) (addresses.get(0).getLongitude());
Log.d("lat-long", "" + lat + "......." + lon);
final LatLng user = new LatLng(lat, lon);
/*used marker for show the location */
Marker hamburg = map.addMarker(new MarkerOptions()
.position(user)
.title(adderess)
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.marker)));
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(user, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
}
catch (IOException e)
{
e.printStackTrace();
}