3

In my Android app I want to give in an EditText field a location/city and by pressing a button I want Google maps to display that specific city.

Is that possible without giving coordinates of the city?

ngrashia
  • 9,869
  • 5
  • 43
  • 58
Radu Stejerean
  • 345
  • 2
  • 13
  • 28

2 Answers2

4

Use the Geocoder to get the coordinates then set the map's center to the result. http://developer.android.com/reference/android/location/Geocoder.html

Philippe Girolami
  • 1,876
  • 1
  • 13
  • 15
3

Use Android - GeoCoder class, get Latitude, longitude from address and using it display location on Google Map..

Geocoder geoCoder = new Geocoder(this, Locale.getDefault());    
    try {
        List<Address> addresses = geoCoder.getFromLocationName(
            "Address", 1);

        if (addresses.size() > 0) {
          GeoPoint p = new GeoPoint(
                    (int) (addresses.get(0).getLatitude() * 1E6), 
                    (int) (addresses.get(0).getLongitude() * 1E6));
        }    
    } catch (IOException e) {
        e.printStackTrace();
    }
user370305
  • 108,599
  • 23
  • 164
  • 151
  • A Complete Tutorial [Using Google Maps in Android](http://mobiforge.com/developing/story/using-google-maps-android) – user370305 Jul 18 '12 at 09:43