user1115684
user1115684

Reputation: 75

Converting an address into geopoint

I want the user to enter the location he wants to search for places that are near by using google places api.I want to know how to convert the string into geopoints?

Upvotes: 2

Views: 3375

Answers (2)

Misha Bhardwaj
Misha Bhardwaj

Reputation: 1387

you can do so by simply calling getFromLocationName()

Geocoder geoCoder = new Geocoder(context, Locale.getDefault());     
 try {
        List<Address> address = geoCoder.getFromLocationName(locationName, 1);    
        double latitude = address.get(0).getLatitude();
        double longitude = address.get(0).getLongitude();            
    } catch (IOException e) {
        e.printStackTrace();
    }

Upvotes: 7

Romin
Romin

Reputation: 8816

You can use the android.location.Geocoder class in Android to get the lat/lon. Check out the documentation here: http://developer.android.com/reference/android/location/Geocoder.html

If you prefer an external API, you can use the Google Geocoding API for the same. The documentation is over here: https://developers.google.com/maps/documentation/geocoding/

Check out this thread for more information/usage: Android geopoint from location/locality

Upvotes: 0

Related Questions