How to get location names nearby my current location using api v2 in android
I am developing an application in which I have to fetch all the location
names nearby my current location(lat/long) and all location should come
under 1000meter radius.
Right now I am hitting below API URL for this:
https://maps.googleapis.com/maps/api/place/search/json?&location=22.724376,75.879668&radius=1000&sensor=false&key=AIzaSyD6Lqfrfx5AEINisuSToz-poqXnwsWSYTY
And I am getting response every time:
{
"debug_info" : [],
"html_attributions" : [],
"results" : [],
"status" : "REQUEST_DENIED"
}
My code:
private String makeUrl(double latitude, double longitude,String place)
{
StringBuilder urlString = new
StringBuilder("https://maps.googleapis.com/maps/api/place
/search/json?");
if (place.equals("")) {
urlString.append("&location=");
urlString.append(Double.toString(latitude));
urlString.append(",");
urlString.append(Double.toString(longitude));
urlString.append("&radius=1000");
//urlString.append("&types="+place);
urlString.append("&sensor=false&key=" + API_KEY);
} else {
urlString.append("&location=");
urlString.append(Double.toString(latitude));
urlString.append(",");
urlString.append(Double.toString(longitude));
urlString.append("&radius=1000");
//urlString.append("&types="+place);
urlString.append("&sensor=false&key=" + API_KEY);
}
return urlString.toString();
}
private String getUrlContents(String theUrl)
{
StringBuilder content = new StringBuilder();
try {
URL url = new URL(theUrl);
URLConnection urlConnection = url.openConnection();
BufferedReader bufferedReader = new BufferedReader(new
InputStreamReader(urlConnection.getInputStream()), 8);
String line;
while ((line = bufferedReader.readLine()) != null)
{
content.append(line + "\n");
}
bufferedReader.close();
}
catch (Exception e)
{
e.printStackTrace();
}
return content.toString();
}
No comments:
Post a Comment