santosh407
santosh407

Reputation: 15

Passing current location ( longitude and latitude ) in the Google Places API

am trying to integrate Google Places API into my app. Now I am finding out my current location of the Phone, how do I embed the longitude and latitude which I have got into the following URL instead of "location=34.0522222,-118.2427778"

"https://maps.googleapis.com/maps/api/place/search/xml?location=34.0522222,-118.2427778&radius=500&types=restaurants&sensor=false&key=Your_API_Key"

Upvotes: 1

Views: 1721

Answers (2)

Colin
Colin

Reputation: 1119

Do you mean how do you do string manipulation such as (untested):

int latitude = ...;
int longitude = ...;
String preamble = "https://maps.googleapis.com/maps/api/place/search/xml?location=";
String postamble = "&radius=500&types=restaurants&sensor=true&key=";
String key = "Your_api_key";
String latStr = latitude + "";
String longStr = longitude + "";
String url = preamble + latStr + "," + longStr + postamble + key;

Upvotes: 2

Dudeist
Dudeist

Reputation: 363

$lat = location[0];
$long = location[1];

Should work, but I use json for geting long and lat from google. Is better. I can check it again if not working.

Here is better json solution:

http://maps.googleapis.com/maps/api/geocode/json?address=Atlantis&sensor=true&oe=utf-8

You should change Atlantis to address

Upvotes: 0

Related Questions