Dale
Dale

Reputation: 619

Android - How to get Google Places data using String address instead of the Place ID?

Is there a way to get the Google Places data (like longitude, latitude, ratings, name, phone number, etc) using just the given address?

Cause i have a long list, like a really long list of address. And i need to get that address to be pointed on a Google Map and in order for me to do so, i need to get does information first from Google.

Upvotes: 1

Views: 865

Answers (2)

AndrewR
AndrewR

Reputation: 10889

You can use the Android Autocomplete or Geocoding Web Service APIs to do this

Upvotes: 0

Bhuvanesh BS
Bhuvanesh BS

Reputation: 13617

You can get latitude and longitude by address. Your code.

public GeoPoint getLocationFromAddress(String strAddress){

Geocoder coder = new Geocoder(this);
List<Address> address;
GeoPoint p1 = null;

try {
    address = coder.getFromLocationName(strAddress,5);
    if (address==null) {
       return null;
    }
    Address location=address.get(0);
    location.getLatitude();
    location.getLongitude();

p1 = new GeoPoint((double) (location.getLatitude() * 1E6),
                  (double) (location.getLongitude() * 1E6));

return p1;
}
}

You have to add the Places library to your project.

compile 'com.google.android.gms:play-services-places:+.'

Upvotes: 1

Related Questions