Google Maps address search for Android?

Asked

Viewed 1,018 times

1

How do I search an address in Google Maps for Android, from the name of the location?

  • in what context? an app with an Edittext doing a query and the map showing the location, a pointer searching directly on the map and showing you a certain position or even you searching your location in real time, through gps? there are several possibilities...

  • This...through an Edittext, type the name of a given address and show the result on the map. I already own the map Activity, what I need now is to add this search bar.

1 answer

1

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();
}
  • How can I connect this code to an Edittext?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.