Using PHP to parse Googlemaps
I have a site that I screen-scrape off GoogleMaps to get the driving distance from one point to another. It isn't heavily used (20 requests per week max), but Google's recent upgrade 开发者_如何学Gobroke this functionality.
I used to use this:
$url = 'http://maps.google.com/maps?f=d&hl=en&saddr='.$start.'&daddr='.$finish.'&output=xml'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec ($ch); if(preg_match('!(\d+).*?.*?(\d+)[^\d]*(\d*)!si', $data, $matches))
And it would return driving distance and total time. The new version of GoogleMaps broke this functionality and I'm trying to figure out a way to deal with the new API.
You do not need to screen scrape. Instead see this SO post:
How to get walking or driving distance via google maps with php
This tells how to do using the API
Scraping is against terms of service, you should use the web services directions api - http://code.google.com/apis/maps/documentation/directions/
精彩评论