I implement to get distance between two location in google map in android but i have not idea how to get travel time for this two location ? I refer many example but i can not understand. Give me example
You can get travel time from [Google Direction API] -
Link: https://developers.google.com/maps/documentation/directions/start#sample-request
Provide your origin & destination in the URL and you'll get a JSON Response.
You can then find travel time in the response as:
routes(JSONArray) -> legs(JSONArray) -> duration(JSONObject)
Reference Link: https://developers.google.com/maps/documentation/directions/intro#DirectionsRequests
Related
I am drawing a polyline on the MapView component from an array of coordinates that I am fetching from my backend server. There is a case when I want the user to open the installed Google Map on their android device with these coordinates and get directions based on that.
I know how to open the Google Map app with a single coordinate, like the following one:
const url = 'geo:37.484847,-122.148386';
Linking.openURL(url);
But, I am not sure (even have no idea if it is possible at all) how would I lunch the Google Map app with a bunch of coordinates and show them as a direction route (blue line).
As an example, If I have 3 points: A, B and C, I want to open the Google Map app and the app should display a direction route made using A to B and B to C.
Just got my answer. Sharing it in case anyone else face the same problem.
We just need to open this url: https://www.google.com/maps/dir/?api=1¶meters with the right parameters. In this case, waypoints. A collection of coordinates need to be passed using the pipe - | operator as the separator. The lat and lon should be separated by a comma.
Google has this documented here: https://developers.google.com/maps/documentation/urls/guide#directions-action
Great. To get the directions by deep linking you need to hit the API with the params as origin and destination . So check this https://www.google.com/maps/dir/?api=1¶meters and in place of params you can replace it with the proper params.
Google has perfectly documented here, google map direction
Hope it helps . feel free for doubts.
How do i use the google maps on android to get the same script as the website
I want it to search the nearest mcdonalds from the location and have all the markers from the website
https://mcdonalds.com.au/find-us/restaurants
That is possible. You can do that using Google Places API and specify in the parameters for types=restaurants.
This is a tested example:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=cruise&types=restaurant&key=YOUR_API_KEY
Now this will fetch all the restaurants in the radius you have defined in the proximity of your current location or the input location.
You can further filter results by writing code that checks if {name name = Mc Donalds} then only fetch the results else {do nothing}. This would give you results just for McDonalds in 500 meter of radius from the specified location.
Hope this Helps!!
I have contacted Open Weather Map support team last week and their forum is dead. Hopefully get some help on here.
I am currently building a weather app for android.
when I send the lat and long for Birmingham UK
which are
lat 52.4447615﹕
lon -1.9292798
it returns Vietnam as the country with a completely different lat lang? I know open weather map is very popular so I must be constructing the url wrong or
something.
http://api.openweathermap.org/data/2.5/weather?q=lat=52.4447462&lon=-1.9292798&units=metric
would really appreciate any help. Thanks,
Matt
It seems the problem is the units argument. Just get rid of it and it works:
http://api.openweathermap.org/data/2.5/weather?lat=52.4447615&lon=-1.9292798
Please note I have not read through the API documentation, just started from their overview page here:
http://openweathermap.org/current.
Try this : [openweathermap.org]1
You can also use Geocoder to get city name from co-ordinates.
I have used Google geo address and using lat/long have got the address. How do I determine if I am on road on not? Basically hit-test for road? I am currently using location manager for lat/long and the GeoAddress is same for on road and next to road.
Final Solution
Use reverse geocoding via the Google Geocoding API.
The term geocoding generally refers to translating a human-readable
address into a location on a map. The process of doing the converse,
translating a location on the map into a human-readable address, is
known as reverse geocoding.
The Geocoding API supports reverse geocoding directly using the latlng
parameter. For example, the following query contains the
latitude/longitude value for a location in Brooklyn:
http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true_or_false
The docs explain how to interpret the json results but StackOverflow has various answers addressing more efficient ways to parse the data.
https://stackoverflow.com/a/8095967/1085891
https://stackoverflow.com/a/8314094/1085891
https://stackoverflow.com/a/6335080/1085891
Possible Solutions
Getting the nearest street/road coordinates in android - the answer to this question may point you in the right direction.
You can use directions api directly: http://maps.googleapis.com/maps/api/directions/json?origin=51,19&destination=51,19&sensor=false
Could you use the API to find directions which would then provide the closest road?
Stick position to road on android maps v2
GPSLocator - App to Find Current (Nearest) Location using GPS - possibly helpful; not so sure on this one.
Snap to Roads Android - Exact same question
Quick Search Results
Snap to nearest street
Maps API Blog using GDirections.loadFromWaypoints
Finding nearest street given a lat-long location
Driving route from my location to destination in Google Maps Android API V2
Unsolved Similar Questions
Trace the location only on Road in Google maps V2 android
https://stackoverflow.com/questions/18081417/google-maps-v2-snap-to-road-issue
See fiddle.
It can be done so much easier with OSRM (nearest) webservice. Make a GET request like:
const url = '//router.project-osrm.org/nearest/v1/driving/';
fetch(url + coord.lon + ',' + coord.lat).then(function(response) {
return response.json();
}).then(function(json) {
if (json.code === 'Ok') {
console.info(json.waypoints[0].location);
}
});
Which is a road/street coordinate.
References — Project-OSRM
I'm building a mobile-version of a website, trying to have one-click link to launch Google Maps with driving directions to the business, from the user's current location. I have it working fine for the iPhone, but when testing on Android, it views 'Current%20Location' and tries to find a business called 'Current Location'. Here is my current code:
Get Directions
I need a universal string to search from the current location, and can't find a definitive answer anywhere online.
Thanks in advance for any help!
I am doing the same thing and now have it working on Android. I don't have an iPhone so I have no way of testing on that. You should leave the saddr parameter blank in the URL, and Google Maps will then prefill it with the user's current location. Also, use + signs instead of spaces in the destination address. Here's the corrected URL:
http://maps.google.com/maps?saddr=&daddr=123+Street+Rd,Cityville,MD,21098
Use the google gps api to get the currentlocation and pass it to maps. Even better I think there's an action to open the built-in maps application asking it to route from current location to your address.
This article on location services should help http://developer.android.com/guide/topics/location/index.html
If you're trying to do it fully through the web, I think the user has to enable location services on the google webpage for it to work.
Also, check out this javascript library that provides a platform neutral api for gps services on most devices http://code.google.com/p/geo-location-javascript/
Google Maps with directions from current location
https://maps.google.com/maps?saddr=&daddr=35.658157,139.697174&sensor=TRUE
https://maps.google.com/maps?saddr=&daddr= PLUS
"location's_latitude" PLUS
"," PLUS
"location's_longitude" PLUS
"&sensor=TRUE" // for getting your current location
Probably the most accurate way using lat and long
<span class="addressAt">
<a href="http://maps.google.com/maps?f=d&hl=en®ion=US&doflg=ptm&geocode=&saddr=&daddr=41.75553,-88.322048" target="_blank">213 S River St
Aurora, IL</a>
</span>
This is the only way to get an accurate "my location" on the google maps mobile site. Replace the coordinates(41.75553,-88.322048) with your locations coords. All other ways just wrote in my location as the start address without actually getting the real time location.