How can I code something which'll calculate the driving distance between 2 zip codes within the USA in PHP. An API or web service that has SOAP or REST will also do.
But I understand GoogleMaps API can't be used because it violates the TOS.. So I need a way without using Google Maps, because I have no intention of using their maps, just calculate the distance.
There isn't a whole lot out there that's free, other than Google Maps. The MapQuest API may give you what you need. Here's their guide to the service - it addresses getting driving distances/times between a set of points. Their terms of service don't appear to require that you display a map, but take a look and see if that meets your needs.
Google Maps Distance API has this exact Functionality. You can get a return as either xml or json.
Here is the documentation
https://developers.google.com/maps/documentation/distancematrix/
Here is a sample of the request url :
http://maps.googleapis.com/maps/api/distancematrix/json?origins=Vancouver+BC|Seattle&destinations=San+Francisco|Victoria+BC&mode=bicycling&language=fr-FR&sensor=false
One nice thing is you dont have to calculate the long/lat first
Related
I have polyline data in mysql. I want to measure its length in php. I have looked distance matrix api. But it requests origin_addresses and destination_addresses , i haven't got those values.
I found decodePolylineToArray gist but when i decode my polyline, there are a lot of values. How can i measure length of polyline? I am using php but if you have a method in another language, i can port it to php.
You need to use Haversine's formula for every Path in the polyline:
http://en.wikipedia.org/wiki/Haversine_formula
For different programming languages search for :
https://www.google.ch/search?q=php+haversine+formula&aq=0&oq=php+Haversine&aqs=chrome.1.57j0l3j62l2.8586&sourceid=chrome&ie=UTF-8
This is a good sample for manual calculation in JS Calculate distance between two points in google maps V3, but there is a simpler way:
google.maps.geometry.spherical.computeDistanceBetween(path.getAt(i), path.getAt(i+1));
Check out this sample:
http://www-users.mat.umk.pl/~kaskader/polyline_simple.html
that uses it.
HTH
I'm essentially trying to build a kind of store locator using Google Maps geocoder, but I want to find a way to write code that returns the nearest stores as hyperlinks on the page (probably inside a div), without placing everything on a map. I don't want to use a map, or markers and infowindows, etc... at least not to begin with.
I've followed a lot of the Google Maps API tutorials online, and it's been easy enough to build a basic working store locator that returns a set number of results inside a given radius by checking the input latlng against the values in my database, but I'm not all that skilled at js, and was wondering if anyone knew of any tutorials that might demonstrate the use of the geocoder for returning latlng search results just in text format, without a map.
Thanks.
The use of the Google geocoder is not allowed without using the results on a Google Map.
Note: the Geocoding API may only be used in conjunction with a Google
map; geocoding results without displaying them on a map is prohibited.
For complete details on allowed usage, consult the Maps API Terms of
Service License Restrictions.
I am looking for driving distance between two address/postcodes with displaying both on Google Map in php
I have search a lot of Scripts but most of them calculation distance only. I also want the both address along Google map also.
like this http://www.1stwebdesigner.com/wp-content/uploads/2010/06/distance-finder/source-distance-finder-google-maps.php
But this link calculate the "straight line distance" between two address and also show them on map
Please help me, i don't want straight line. I want driving calculation alone with map.(The script also show address on Google map)
You can do this with the API, I suggest you 'google' the google API for specifics, the documentation for google maps v3+ is awesome, you should have no problem if you're not reaching way outside your knowledge base.
and +1 #HeitorChang for that comment, I didn't see it.
What I'm trying to create, is an app that will allow me to download list of places near given coordinates. With Wikipedia api it's fairly simple:
http://api.geonames.org/findNearbyWikipedia?lat=47&lng=9&username=some-username
This code run with curl in php gives me an xml response with list of places and possibly their descriptions along with exact coordinates matching the given ones (which are not exact). Is there a way I can do it as simple as above, with GoogleApi? This link: http://code.google.com/intl/pl/apis/maps/documentation/mapsdata/developers_guide_protocol.html#SpatialSearch tells very briefly about spatial search, and I can't find any info on this topic in the internet - like where can I find my user and mapid, how can I get my authorization token.
I know, that this may seem a stupid question for you, but google maps api doc is vast, and I just can't find anything more, than in this link above.
In sum:
I don't want to embed google map on my page, I just want to get places near given coordinates, and list them to my users, and I have to do this on server-side.
At the very top of that page, it says "Google Maps Data API (No Longer Available)", so I don't think you should use that.
Instead, look at Google Places API. It's only a developer preview, but looks like what you need.
Google maps has a function that lets you retreive the distance between two points: getDistance(), of the GDirections class.
Now, this is Javascript, so it'll only be able to calculate once the page has loaded.
My search form however, has the ability to indicate what's the maximum distance you want between yourself and another person and based on that, a list of search results has to be provided.
Since I can't use this function in PHP, is there another way for me to calculate the distance between 2 points on the earth? By giving up the street, postal code and city name, just like what Google maps needs.
This page has a list of google maps parameters for use in http connection. By specifying the output paramter you can choose to give back kml files or similar and can be used in any lanuage that can make http connections.
Looks like you want to calculate a Great Circle Distance
Formulas have been discussed here on stackoverflow before.
A point on earth is defined by it's latitude and longitude. If you want to calculate the distance between 2 points on earth by giving up the street, postal code and city name, you will need geo-referene data.
This data is available for free on the internet, but the accuracy and availability differ greatly from region to region. (USA data is of good quality, data for Kenia for example will be harder to come by)
So to answer your question:
Yes, there are other ways to calculate what you want. But they require more work/are more complex than just querying the google API.
You might want tot read: Creating a Store Locator with PHP, MySQL & Google Maps
Hope this points you into the right direction.
You can use kml file. It's xml-formatted file that you can recieve by link like http://maps.google.com/maps?f=d&hl=en&saddr=<src latitude>,<src longitude>&daddr=<dist latitude>,<dist longitude>&ie=UTF8&0&om=0&output=kml
in recieved file you can parse and summate distances from