I tried to display route, distance and duration using Distance Matrix of google from 2 location (it sets by Latitude and longitude). but it always give me an error like this :
{
"destination_addresses" : [],
"origin_addresses" : [],
"rows" : [],
"status" : "INVALID_REQUEST"
}
here is my url :
https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origin=-8.60821861,115.18293077&destination=-8.6947,115.263&key=KEY_SERVER
but, when i using name of city to set the origin and the destination it works well.
like this :
https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=Bandung&destinations=Jakarta&key=KEY_SERVER
the result when using name of city :
{
"destination_addresses" : [ "Jakarta, Special Capital Region of Jakarta, Indonesia" ],
"origin_addresses" : [ "Bandung, Bandung City, West Java, Indonesia" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "94.1 mi",
"value" : 151394
},
"duration" : {
"text" : "2 hours 30 mins",
"value" : 8984
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
what should i do to set the origin and destination by latitude or longitude in order to get the result like above?
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.
Okay, so I have my distance matrix request responding as if I didn't pass it an arrival time.
https://maps.googleapis.com/maps/api/distancematrix/json?origins=875+Centerville+Road+Rhode+Island&destinations=1+New+England+Tech+Blvd&key=AIzaSyAkoZCNoX406xz-mmv2_O9Hji7oAkcoN7g&transit_mode=bus&arrival_time=194976000&sensor=false
This is the response I get back even with the arrival time parameter specified...
{
"destination_addresses" : [ "1 New England Tech Boulevard, East Greenwich, RI 02818, USA" ],
"origin_addresses" : [ "875 Centerville Rd, Warwick, RI 02886, USA" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "5.0 km",
"value" : 5048
},
"duration" : {
"text" : "8 mins",
"value" : 488
},
"status" : "OK"
}
]
}
], "status" : "OK"
}
I get the same response if the url I pass is as follows...
https://maps.googleapis.com/maps/api/distancematrix/json?origins=875+Centerville+Road+Rhode+Island&destinations=1+New+England+Tech+Blvd&key=AIzaSyAkoZCNoX406xz-mmv2_O9Hji7oAkcoN7g
I get the same result whether or not I pass the arrival time...
{
"destination_addresses" : [ "1 New England Tech Boulevard, East Greenwich, RI 02818, USA" ],
"origin_addresses" : [ "875 Centerville Rd, Warwick, RI 02886, USA" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "5.0 km",
"value" : 5048
},
"duration" : {
"text" : "8 mins",
"value" : 488
},
"status" : "OK"
}
]
}
], "status" : "OK"
}
Can someone please tell me what I'm doing wrong. I need the API to respond with what time I will need to leave, to arrive at a specified time that I pass it.
I've not found a working example and this part is crucial to my application. Thank you.
I have a working response for the departure time parameter...but doing the same with the arrival time doesn't work. Does this API not actually work for the arrival time?
https://maps.googleapis.com/maps/api/distancematrix/json?origins=875+centerville+road+Rhode+Island&destinations=1+new+england+tech+blvd+rhode+island&key=AIzaSyAkoZCNoX406xz-mmv2_O9Hji7oAkcoN7g&transit_mode=bus&departure_time=1949794160
{
"destination_addresses" : [ "1 New England Tech Boulevard, East Greenwich, RI 02818, USA" ],
"origin_addresses" : [ "875 Centerville Rd, Warwick, RI 02886, USA" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "5.0 km",
"value" : 5048
},
"duration" : {
"text" : "8 mins",
"value" : 488
},
"duration_in_traffic" : {
"text" : "7 mins",
"value" : 432
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
I'm trying to build an app that would display the location name of a nearby place as well as its photo. I'm using Google Places API.
I would like to quickly convert photo_reference to the photo url.
Currently, if you do a nearby search, you would get back this json with 20 nearby locations (I have just pasted 2 locations as the json is too long):
{
"html_attributions" : [
"Listings by \u003ca href=\"http://www.easyinfo.co.za/\"\u003eEasyinfo.co.za\u003c/a\u003e"
],
"next_page_token" : "CvQB7AAAAEIeM4orJZv2oOV0Lt_mhGBbkvvJIyOwjcHeStpcC5E6fR7pNHw4VsS6cMSKzFRtyjr2LQ67GSvZwFGxw8f72sxwO6NggFNsSyakjO9bKovKpjCn4-uHoQyXESaxMqMci1fet-n9EJEp-VoBVXv-iIb_TvSO26iIXkGUeO-09-19ucYirFahOaNF0pp8ttod59XWgsLPs5r1PnkakrYj5JBgawP83T0ZMwIY52oViQJNGvR6_Bpf73dK68iUnj24w5QNZOql6uAlvFAg-BXs5FKjTWvQO0nR5woo5mJjDzYvbaxQkpMqFQ-BMEnZ3RX10xIQ3twWZWnygJl78DhqZH1DkBoUdcq5qakPBsg1QAn6BdcqdrQFz2g",
"results" : [
{
"geometry" : {
"location" : {
"lat" : -26.2020253,
"lng" : 28.0500779
},
"viewport" : {
"northeast" : {
"lat" : -26.2003339,
"lng" : 28.054075
},
"southwest" : {
"lat" : -26.2041059,
"lng" : 28.0470949
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id" : "0765607c0fdb4fae92e59390aff8e9501e98e59c",
"name" : "Fashion District",
"place_id" : "ChIJ2Vn0h5wOlR4RsOSteUYYM6g",
"reference" : "CpQBkAAAADboZMmtzHTuxZ85pPFK1fr-V0QslLUKBr8QZssBme4qcqLqs7SvrW-L2lJZg3S0PBYTGzuBU8M1F-Ll72tOdto-hfnxOCBOFfVIQEYe264r-IbWZjiFbuqOHBtU5z99jo3NrTxI29MvE8ogUYccX8FukX8eoAcpKti3Ik2VLvDziRKArf2EDy-6CtSbxeCnthIQyHx09QzBQ-pWEelLd6tCsxoUklzTqP7XbT6WbDCbIa42k1R4Iic",
"scope" : "GOOGLE",
"types" : [ "neighborhood", "political" ],
"vicinity" : "Johannesburg"
},
{
"geometry" : {
"location" : {
"lat" : -26.205586,
"lng" : 28.046573
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
"id" : "671355d0ee1b5b0bbc1556321cea85ca164601de",
"name" : "KFC Carlton Centre",
"opening_hours" : {
"open_now" : true,
"weekday_text" : []
},
"photos" : [
{
"height" : 296,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/106295947298714161198\"\u003eKFC Carlton Centre\u003c/a\u003e"
],
"photo_reference" : "CmRdAAAAHcsAE2aiv5lIxLEo0c9xMUmH-chXoAeq6yrFPw5uy7LdppAMxBmg8_yvG9y9qaXqsH-IrcPsBD6QQvsfZnpml3U5zgh93nTbm5WONnYmutBSltIr9FwuK-awm8l1vyKeEhD9AqZpJwFLIWms2GeZGPR2GhSPp1JyAU_6_s1Im1_oH5tB4IjyXQ",
"width" : 607
}
],
"place_id" : "ChIJTQABc5kOlR4RAzBKVJ-lZNo",
"price_level" : 1,
"rating" : 3.7,
"reference" : "CnRmAAAAyOipUqSqkrpsKw96nu3YnT72kF2Yj_FWAd3wJkzM6a73ZZu8AJIXGsS-EmvugVGsgcEEcadiPfLJCdX3_molaMarh-sox9sIDp5M9LE6xhE1U-6WMXarQEjNu6_ATfQMdaR0nJPpxCX_AS2vbym1wBIQAA9yUjeeEXHF-HDsjTj9kBoUvRoUMWlNtyY30v0iWqMUzstMHOE",
"scope" : "GOOGLE",
"types" : [ "restaurant", "food", "point_of_interest", "establishment" ],
"vicinity" : "Commissioner Street, Carlton Centre, Johannesburg"
}
To get the photo url, you will have to call the following for each of the 20 photo_reference in the json - these calls to the google servers take a lot of time to return as you are calling the server 20 individual times:
https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference=CmRdAAAAHcsAE2aiv5lIxLEo0c9xMUmH-chXoAeq6yrFPw5uy7LdppAMxBmg8_yvG9y9qaXqsH-IrcPsBD6QQvsfZnpml3U5zgh93nTbm5WONnYmutBSltIr9FwuK-awm8l1vyKeEhD9AqZpJwFLIWms2GeZGPR2GhSPp1JyAU_6_s1Im1_oH5tB4IjyXQ&key=API-KEY
Each call returns something similar to this which is the actual url for the image - if you click the link below, it goes to the actual picture.
https://lh3.googleusercontent.com/-B8FWOhhu2_k/VTdYJeFjRhI/AAAAAAAAAD8/JSJamjx4XyA/s1600-w400/
I think this is a highly inefficient way to obtain the links for the place photos, my rest API calls sometime returns after 10 seconds. Is there a way to do this efficiently?
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",