In my project I pass the origin address and destination address, but not get the distance.
origin address-:south africa
destination address-:india
url-:https://maps.googleapis.com/maps/api/directions/json?origin=south%20africa&destination=india&key=GOOGLE_API_KEY
Response-:
{
"geocoded_waypoints" : [
{
"geocoder_status" : "OK",
"place_id" : "ChIJURLu2YmmNBwRoOikHwxjXeg",
"types" : [ "country", "political" ]
},
{
"geocoder_status" : "OK",
"place_id" : "ChIJkbeSa_BfYzARphNChaFPjNc",
"types" : [ "country", "political" ]
}
],
"routes" : [],
"status" : "ZERO_RESULTS"
}
noroutes found so how can get distance between two country
Get the distance between the two countries? Don't use google maps. Create a Location object for each and call Location.distanceTo(). Google maps would only possibly help if you wanted a land route.
Related
I've been using Google place API on old projects, but on those projects I had to pick a place and then, the API returned to me information about that place...
The thing is with this same API can I ask for a place for example Restaurant X, and then I get a json or xml with all of those Restaurant X (nearby or not)?
Or if it's another API to get places without having to pick them manually feel free to say it to me.
EDIT
I've found a tutorial but it's kinda old... but the thing is that I've implement all of those stuff and when I click on any item from the Spinner nothing changes...
And I think I'm calling correct the API
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=41.493375,2.354788333333333&radius=5000&types=restaurant&sensor=true&key=AIzaSyBXxZ6lF5WGqCi4ToRJoFihTxGOVzC5vGE
The Google Places API has a REST end-point that you could use to get back details of places of various types within the vicinity you provided.
For example, this end-point https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=44.661704,%20-63.609050&radius=2000&types=restaurant&name=thai&key=XXXX would return back all 'restaurants' that has a name 'thai' in it as a JSON.
The result would be something like this:
"html_attributions" : [],
"results" : [
{
"geometry" : {
"location" : {
"lat" : 44.6496741,
"lng" : -63.61783519999999
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
"id" : "00b680706e7d8085d4b010b2d99789d8d046f9aa",
"name" : "Thai Express",
"opening_hours" : {
"open_now" : true,
"weekday_text" : []
},
"photos" : [
{
"height" : 517,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/104629276961555072183/photos\"\u003eThai Express\u003c/a\u003e"
],
"photo_reference" : "CmRdAAAAJktMRG2eiCnmejhFOWMYxdpUq97IpUv407jlwfWGAPVVaksJsk36Cbv6ZONNfGs92kEA1Wtgw_4V_dCz5PhABknBl8eR-XIkloEQF2Cs9XmQbmQmV3lW5Q6hz4DYtPJwEhBuQUr3CwPP4dJmBnBfkLLmGhSB76vOFUm-NA_ab42xrdAPDhoq0A",
"width" : 1562
}
],
"place_id" : "ChIJa6gRMpghWksRHseXPRkQT6c",
"reference" : "CmRgAAAARuvIKASXzP7UxvFCd3dZ8TnIX58O2SHrtySdT09_HjwYFld8ktryg3mEvIyf-utJhnjPxJ74dV1Vk6slCTwdL3NOW4MYpDkyh3v1lCXYG1bdFw-QzchfeFC-KISlRkbWEhD_iDkV6G1ctXxnALq-rlyAGhTHCjz-C9bbQ9eE2NZeX34--ficrA",
"scope" : "GOOGLE",
"types" : [
"meal_takeaway",
"meal_delivery",
"restaurant",
"food",
"point_of_interest",
"establishment"
],
"vicinity" : "7001 Mumford Road, Halifax"
}
],
"status" : "OK"
}
More details about the Places API Web Service are here - https://developers.google.com/places/web-service/intro. The supported types you could search for are here - https://developers.google.com/places/supported_types.
Hope this answers your question.
I offer to users to create an event at some specific place, I use Google places API to auto complete address. So when user types "New Yor" it might offer him "New York, Central Park". If he chooses that, the whole address is saved in database + latitude and longitude of the address.
The problem comes now, when another user wants to see all events from the New York.
Since service I am using doesn't support wild card search, I am looking for a way to see if New York latitude and longitude includes New York, Central Park latitude and longitude.
Any idea?
Some code:
uri = "https://www.maps.google.com/maps/api/geocode/json?address=" +
URLEncoder.encode(params[0].toString(), "UTF-8") +
"&sensor=false";
When you save the results of just the "New York" search, be sure to save the latitude/longitude bounds as well.
http://maps.google.com/maps/api/geocode/json?address=new%20york
The bounds are in the JSON under results->geometry->bounds
{
"results" : [
{
"address_components" : [
{
"long_name" : "New York",
"short_name" : "NY",
"types" : [ "locality", "political" ]
},
{
"long_name" : "New York",
"short_name" : "NY",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "New York, NY, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 40.91525559999999,
"lng" : -73.70027209999999
},
"southwest" : {
"lat" : 40.4913686,
"lng" : -74.25908989999999
}
},
"location" : {
"lat" : 40.7127837,
"lng" : -74.0059413
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 40.91525559999999,
"lng" : -73.70027209999999
},
"southwest" : {
"lat" : 40.4913686,
"lng" : -74.25908989999999
}
}
},
"types" : [ "locality", "political" ]
}
],
"status" : "OK"
}
Now when you want to see if "New York Central Park" is within "New York", do a simple check to see if central park's lat/long is greater than the southwest boundary, but less than the northeast boundary.
When doing a autocomplete API call for a location, I request a JSON response from google.
What is the difference between the "id" and "place_id" string?
Are these two id's unique to any city in the world?
Does google places assign every city in the world an id?
For example, does Somers, NY, USA have the same id as Somers, New York, United States?
Is there an easy way to get an id for a city? (from a google maps url or something?)
Here is the JSON response from a autocomplete api call of Somers NY USA:
{
"html_attributions" : [],
"result" : {
"address_components" : [
{
"long_name" : "Somers",
"short_name" : "Somers",
"types" : [ "administrative_area_level_3", "political" ]
},
{
"long_name" : "Westchester County",
"short_name" : "Westchester County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "New York",
"short_name" : "NY",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"adr_address" : "\u003cspan class=\"locality\"\u003eSomers\u003c/span\u003e, \u003cspan class=\"region\"\u003eNY\u003c/span\u003e, \u003cspan class=\"country-name\"\u003eUSA\u003c/span\u003e",
"formatted_address" : "Somers, NY, USA",
"geometry" : {
"location" : {
"lat" : 41.29963050000001,
"lng" : -73.7360175
},
"viewport" : {
"northeast" : {
"lat" : 41.3550988,
"lng" : -73.65881709999999
},
"southwest" : {
"lat" : 41.2379047,
"lng" : -73.78000709999999
}
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id" : "8e846f7cdf419380d138e6d605137e739075b777",
"name" : "Somers",
"place_id" : "ChIJ6wv7yGixwokRIwjh6OWI4I0",
"reference" : "CoQBcgAAAKxvwwjlyK3ZaVA5DAM52DU8tMMplyvamYxXVJuMyDplQ3SUs-9ONvZgIN4sDW_sUz9z7wdoBCmPcgWHY9Oi_l0hImvMtiE8s6TKaUCDju2vzlcSEGXtDW0bvixVbbuF35AP2stRw80YjcrnwuMDglKEHKUVdH8vzSVG91WNOcOcEhBda300E-VstT6ZQ1zCx30eGhQBUGcFLuUeB484h1AzDw75Aw5wxA",
"scope" : "GOOGLE",
"types" : [ "administrative_area_level_3", "political" ],
"url" : "https://maps.google.com/maps/place?q=Somers,+NY,+USA&ftid=0x89c2b168c8fb0beb:0x8de088e5e8e10823"
},
"status" : "OK"
}
"id" and "reference" have been deprecated and will be removed from the results in mid-2015. They were not "unique" in the sense that you could look up somewhere from that info.
Placeid is different - it is both unique to the location and the location generally only has one Placeid. (This is true in most cases. However a "place" can have additional IDs that refer to different scopes (Google scope vs user scope) or if a business has moved to a different place giving it a new place_id. However in all cases, place_id is still persistent.) Furthermore you use the Placeid to access the Details API.
See the deprecation notice here: https://developers.google.com/places/documentation/search
Note: The id and reference fields are deprecated as of June 24, 2014.
They are replaced by the new place ID, a unique identifier that can be
used to compare places and to retrieve information about a place. The
Places API currently returns a place_id in all responses, and accepts
a placeid in the Place Details and Place Delete requests. Soon after
June 24, 2015, the API will stop returning the id and reference fields
in responses. Some time later, the API will no longer accept the
reference in requests. We recommend that you update your code to use
the new place ID instead of id and reference as soon as possible.
I am trying to plot a location on android google map v2. As in google map implementation in phone, when a user starts typing, I fetch the location suggestions using places api and displays the same as autocomplete suggestions. This is the tutorial I referred and the places api url I used to fetch suggestions as given in the tutorial is:
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Newyor&types=geocode&language=en&sensor=true&key=mykey
And a typical response from places api would be:
{
"predictions" : [
{
"description" : "Pune, Maharashtra, India",
"id" : "b53b6db33aaf3aa06dc661e9b2631735f3d484f1",
"matched_substrings" : [
{
"length" : 3,
"offset" : 0
}
],
"reference" : "CjQwAAAAMoxQRyAwsRv2ORCTdAedR1nQYCErx3mhuiabdfgKaFVn9ptmcBjr6F5zgNpLoF41EhBCLLKBfB7Bm0Vkm6EB7jxKGhSKJt0vahFMJ2GfYLk2uMcBC0Vl5g",
"terms" : [
{
"offset" : 0,
"value" : "Pune"
},
{
"offset" : 6,
"value" : "Maharashtra"
},
{
"offset" : 19,
"value" : "India"
}
],
"types" : [ "locality", "political", "geocode" ]
},
{
"description" : "Punjab, Pakistan",
"id" : "97a12ea9bc0c551167da68d14e152d70e68150df",
"matched_substrings" : [
{
"length" : 3,
"offset" : 0
}
],
"reference" : "CjQoAAAA0_J5uM7i32DiX4jRXiY8jMp54QBdU7N2vE5XE4IdFbesDW_qdDKQsQ8No7zdjRjFEhC4MJu4F86xTjBYLR9VOEBFGhSELemilA35vFobxi2Z45JvFXM0eQ",
"terms" : [
{
"offset" : 0,
"value" : "Punjab"
},
{
"offset" : 8,
"value" : "Pakistan"
}
],
"types" : [ "administrative_area_level_1", "political", "geocode" ]
},
Are there any parameters in the above response which I can make use of in order to plot a map or do I need to make another api call in order to get latitude and longitude of the place which i select from the above "description" key in the json response? If I need to make an api call again, what are the parameters I need to pass from the above json response.
Or in first place, is there an api already available from which I get the lat, long also along with the places suggestion?
Any help is appreciated.
In first place, is there an api already available from which I get the
lat, long also along with the places suggestion?
Yes, for getting (LatLong from Address):
http://maps.googleapis.com/maps/api/geocode/json?address=NewYork&sensor=true
& for getting (Adress from LatLong):
http://maps.googleapis.com/maps/api/geocode/json?latlng=40.9152555,-73.700272&sensor=true
So I'm running the following Google Places API call:
https://maps.googleapis.com/maps/api/place/search/json?location=34.0467359,-118.441764&rankby=distance&sensor=true&key=MY_API_KEY&types=restaurant
part of my JSON output is:
"results" : [
{
"geometry" : {
"location" : {
"lat" : 34.047332,
"lng" : -118.443431
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
"id" : "03ed19ca32b20080897e31095e6eed2715cde819",
"name" : "Del Taco",
"opening_hours" : {
"open_now" : true
},
"price_level" : 1,
"reference" : "CnRrAAAA6Dqit_GeW6rLNFXGo4cb-SBPdIr09vVlvU7n2W8QVesy6svOTDQu-lkhbdWPBPM64uR3a8pwer_dwbwi1weyKXIhTYAa0deSu4-Xp3S8K2LvPexGFCd7oasJ1dK8ZtCAA4IvwQbpkM6GaJ9xCn1jqRIQ63-ofgMIddQpjtHoJcOlVhoUDwWYwlyV3hyVg-4jYExfcPPxhU4",
"types" : [ "restaurant", "food", "establishment" ],
"vicinity" : "11066 Santa Monica Blvd, Los Angeles"
},
{
"geometry" : {
"location" : {
"lat" : 34.047475,
"lng" : -118.443474
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
"id" : "6e6ae3ea79f06eb6c790ed533a35d9b3abc6c344",
"name" : "Moon House Chinese Cuisine",
"opening_hours" : {
"open_now" : true
},
"price_level" : 1,
"reference" : "CoQBfAAAAFmSc3ErmitzFoxmNvuNXG5x0iJCWpXITFr9VtKcA5SRpcSyXmFW9LR_F2vLVUC4dCCSo7xQm_l_JaOuAttZmYJDonYNnobGAT6fVXR1Gw_p3lmJWwKgd7zTqeMCGXPk8kBT6ztYWzLpTEnKtg2u9jFRvYUerdBsv1Keso3yXVESEhBGizJBrGPMBDz2nte3wF81GhQ21SBkMNMSG6Bx0Ymi65rr2jyQBg",
"types" : [ "restaurant", "food", "establishment" ],
"vicinity" : "11058 Santa Monica Blvd, Los Angeles"
},
I check the JSON that's returned, I don't even see the "reviews" array. but I check the google maps for the same place and I can see that there are a few reviews. Any idea why it wouldn't include that?
Allright the problem is that place API doesen't include reviews. But if u want to get reviews then u have to make place detail request.
eg: this is sample place request
https://maps.googleapis.com/maps/api/place/nearbysearch/json?
location=34.0467359,-118.441764&radius=1000&sensor=true
&key=YOUR_PLACE_API_KEY&types=restaurant
this is sample place details request
https://maps.googleapis.com/maps/api/place/details/json?
reference=REFERENCE_STRING_OF_THE_PLACE&sensor=true&key=YOUR_PLACE_API_KEY
Instead of search use near by search as follows:-
and also include radius :
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=34.0467359,-118.441764&radius=50000&sensor=true&key=MY_API_KEY&types=restaurant
You can get review array by place detail API
https://maps.googleapis.com/maps/api/place/details/json?placeid={place_id}&key={api_key}
where place id is results id field from your response,
Ex. "id" : "03ed19ca32b20080897e31095e6eed2715cde819",