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?

Nishanthi Grashia
  • 9,787
  • 5
  • 42
  • 57
Radu Stejerean
  • 347
  • 2
  • 12
  • 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,866
  • 1
  • 13
  • 14
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
  • 106,566
  • 23
  • 160
  • 150
  • A Complete Tutorial [Using Google Maps in Android](http://mobiforge.com/developing/story/using-google-maps-android) – user370305 Jul 18 '12 at 09:43