I am looking at the Google-Distance matrix here
According to Docs if we provide latitude & longitude values we we be replied back with information back from google
I tested with a sample :: Latitude=12.918494 Longitude=77.669387
http://maps.googleapis.com/maps/api/distancematrix/json?origins=12.918494,77.669387&destinations=12.961323,77.647415&language=tr-TR&sensor=false&option=driving&units=metric
I got a JSON response::
{
"destination_addresses" : [
"28, 4th Cross Road, HAL 3rd Stage, Hal, Puttappa layout, New Thippasandra, Bangalore, Karnataka 560008, Hindistan"
],
"origin_addresses" : [
"14, Sarjapur Main Road, Ambalipura, Harlur, Bangalore, Karnataka 560102, Hindistan"
],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "10,5 km",
"value" : 10544
},
"duration" : {
"text" : "19 dakika",
"value" : 1119
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
What i am trying to achieve::
I want to get the value Bangalore(cityname) from the Json
I could parse the Json and get it but problem is if say we give some
other co-ordinates the address could be longer and seperated by
coma's so i can't predict where the cityname will be
What i am trying to achieve::
Is there a way like a function using which i can get the Bangalore as we do in Geocoder
Note:: I dont wan't to use geocode & i am trying to achieve using this
I am new to android, please go easy with answers
Hope i am clear, Thanks
Related
I'm developing a delivery android app, i let the user to input 2 points then i draw the polygon after hitting a request to https://maps.googleapis.com/maps/api/directions/ this seems fine and it produces json like this part
"steps" : [
{
"distance" : {
"text" : "1 m",
"value" : 0
},
"duration" : {
"text" : "1 min",
"value" : 0
},
"end_location" : {
"lat" : 30.2032168,
"lng" : 35.4687987
},
"html_instructions" : "Head on \u003cb\u003eKings Hwy.\u003c/b\u003e/\u003cb\u003eRoute 35\u003c/b\u003e",
"polyline" : {
"points" : "cajwD_onwE"
},
"start_location" : {
"lat" : 30.2032168,
"lng" : 35.4687987
},
"travel_mode" : "DRIVING"
}
],
"traffic_speed_entry" : [],
"via_waypoint" : []
}
],
well, it seems all good so far, my problem is how to get the real time? i mean when the driver starts driving i need to update my estimation time based on car speed,
it's hard to make an httprequest every 5 seconds, because the json file will need a lot of calculation as you see json file is just 5% of the whole json response regardless to the internet speed,they all need a huge time and it will drain the battery, is there a way to pull the time direct for the original google map ?
So I have the Json in following format on firebase:
{
"30000000549656652" : {
"cast" : [ {
"src" : "https://encrypted-tbn1.gstatic.com/images",
"title" : "Hilary Duff (Samantha \"Sam\" Montgomery)"
}],
"channel_name" : "HBO",
"desc" : "After her .....",
"extras" : {
"initial" : "July 10, 2004 (Hollywood)",
"director" : "Mark Rosman",
"screenplay" : "Leigh Dunlap"
},
"genre" : "Thriller",
"lang" : "English",
"movie" : 1,
"prog_id" : 30000000549656652,
"prog_img" : "http://images."
"ratings" : {
"IMDb" : "5.9/10",
"Metacritic" : "25%",
"Rotten Tomatoes" : "11%"
},
"start" : 201607141800,
"stop" : 201607141700,
"title" : "Thrill A Cinderella Story",
"year" : "2004"
},
.....
}
I want to do the following in activity on my android app-
Query the node in which these JSON exist, then filter them such that i get all the results which have movies of one specific genre(e.g., Thriller) and the year is within five yrs less or five yrs more of the one i would pass in the query.
Like i would want to query to get all thriller movies whose "year" are between 2000 and 2009.
Can someone please help me to build such query for a json like this. Thanks!
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?
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 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