Search code examples
androiddictionarylocationandroid-edittextgeopoints

Getting the latitude and longitude of an EditText location Android


Ok, so what I'm trying to do is have an EditText box in which the user can enter a street name. My application will then get the lat/long of that street and place a marker at that geopoint location on a map (Using the Google Maps API v2). So far I Have the EditText box set up as well as a map with a function to manually add markers at specified geopoints.

Example: If the user enters "Grafton Street" in the EditText box, the application will get the lat/long (53.342094,-6.259868) and subsequently place a marker at that point on the map using the GeoPoint function, or maybe even highlight the whole road (as seen in Google directions etc).

My problem is that I'm unsure how to actually get the latitude and longitude of the entered location to pass into my addMarker function. Any ideas or suggestions would be greatly appreciated!

EDIT: Solved, see my answer below.


Solution

  • First, you will need to use GoeCoder to get name and convert it to Lat\Long:

    http://developer.android.com/reference/android/location/Geocoder.html

    Then you will use GeoPoint to get a lat\long as an argument, and convert it to a a GeoPoint (for display on a Map).

    https://developers.google.com/maps/documentation/android/v1/reference/com/google/android/maps/GeoPoint