View previous topic :: View next topic |
Author |
Message |
hemmeter Smarty Rookie
Joined: 23 Aug 2006 Posts: 12 Location: California
|
Posted: Sun Aug 27, 2006 3:00 am Post subject: addMarkerByAddress not responding in GoogleMapAPI |
|
|
Has anyone noticed that on and off over the past 2 days, the addMarkerByAddress() method is not responding? I have been testing it lately and have been finding that the code is getting hung up when it gets to the geoGetCoords() call.
I thought it was my code, so I tried calling the method with the example lines from http://www.phpinsider.com/php/code/GoogleMapAPI/ and it was not responding. I then tried using using addMarkerByCoords() and it worked fine. This was yesterday afternoon. I decided to wait a while to rerun the addMarkerByAddress() method. Yesterday evening it came back online and everything worked fine.
Today it is not working again. Same code. No changes. I will wait and see if it starts working again later this evening or tomorrow and post back.
Has anyone been experiencing this over the past 2 days?
Is there a URL I could put into my browser to test whether the Geocode API is up and running? In the geoGetCoords() method, the following line builds the URL string.
Code: | $_url = sprintf('http://maps.google.com/maps?output=js&q=%s',rawurlencode($address)); |
Thanks. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Aug 28, 2006 2:57 am Post subject: |
|
|
You are at the mercy of the google javascript giving you the lookup codes. I haven't been having problems, but I may have different lookups and/or intervals than you. As the docs state, the Google lookups are not offically supported APIs, so use at your own risk. The Yahoo API lookups are official, but afaik they only work for US addresses. |
|
Back to top |
|
hemmeter Smarty Rookie
Joined: 23 Aug 2006 Posts: 12 Location: California
|
Posted: Wed Aug 30, 2006 7:31 pm Post subject: |
|
|
The issue is happening right now. It seems to start around 11am PST everyday and last for most of the rest of the day. Is it possible that the preg_match function is not setup to account for changes in the API response during different parts of the day?
If you see this soon, see if you are able to use the AddMarkerByAddress function using Google as the lookup service. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Aug 30, 2006 8:43 pm Post subject: |
|
|
Do you have a sample address? It is working fine for me. |
|
Back to top |
|
hemmeter Smarty Rookie
Joined: 23 Aug 2006 Posts: 12 Location: California
|
Posted: Wed Aug 30, 2006 8:54 pm Post subject: |
|
|
While it wasn't functioning, I decided to echo the $_result variable in the geoGetCoords() method. Interesting results. I get the following returned from Google.
Of course, this is not a virus or spyware. I am merely querying a set of records and adding their markers onto the map. They must monitor usage and cut you off at certain limits.
This, of course, is the issue with using a beta API.
Last edited by hemmeter on Wed Aug 30, 2006 9:08 pm; edited 1 time in total |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Aug 30, 2006 9:05 pm Post subject: |
|
|
How many requests do you routinely do? Make absolutely sure that you use the geocode lookup cache. My guess is that you lookup too often, and google shuts you off. I've done about 1500 lookups in a row (initially seeding a database of addresses) and didn't have any problems, but your mileage may vary.
Like I've said in the docs, the google lookup is more or less a hack, and not something officially supported by either GoogleMapAPI or Google. Try the Yahoo API, see if you have better results? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Aug 30, 2006 9:21 pm Post subject: |
|
|
Please grab the latest CVS, see if this lookup works any better. |
|
Back to top |
|
hemmeter Smarty Rookie
Joined: 23 Aug 2006 Posts: 12 Location: California
|
Posted: Wed Aug 30, 2006 9:44 pm Post subject: |
|
|
Sorry, but I am not well versed in some basic things like CVS. I tried downloading WinCVS, but can't figure out how to get it to connect to cvs.phpinsider.com. Anyway, can you email me the PHP file? |
|
Back to top |
|
hemmeter Smarty Rookie
Joined: 23 Aug 2006 Posts: 12 Location: California
|
Posted: Thu Aug 31, 2006 12:08 am Post subject: |
|
|
I didn't get a chance to download your file because I don't know how to use CVS. Instead, I tried doing this on my own and came up with a good solution.
1.) I downloaded the JSON.php file from the PEAR website. This package allows you to read JSON objects and decode them into stdObjects.
2.) I added the following line to the GoogleMapAPI.class.php file
[php:1:ab2e966d75]include('JSON.php');[/php:1:ab2e966d75]
3.) I rewrote the GOOGLE case in the geoGetCoords() method
[php:1:ab2e966d75] $_url = sprintf('http://maps.google.com/maps/geo?output=json&key=%s&q=%s',$this->api_key,rawurlencode($address));
$_result = false;
if($_result = $this->fetchURL($_url)) {
$json = new Services_JSON();
$value = $json->decode($_result);
if ($value->Status->code != "200") {
return false;
} else {
$_coords['lon'] = $value->Placemark[0]->Point->coordinates[0];
$_coords['lat'] = $value->Placemark[0]->Point->coordinates[1];
}
}
break;
[/php:1:ab2e966d75]
NOTE: I was having trouble getting the file_get_contents to read as XML where I'd be able to use the built in SimpleXML methods. So I went to the JSON option.
Thoughts? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Aug 31, 2006 12:16 am Post subject: |
|
|
I just used the csv output, no json required.
[php:1:406853f338]
case 'GOOGLE':
$_url = sprintf('http://%s/maps/geo?&q=%s&output=csv&key=%s',$this->lookup_server['GOOGLE'],rawurlencode($address),$this->api_key);
$_result = false;
if($_result = $this->fetchURL($_url)) {
$_result_parts = explode(',',$_result);
if($_result_parts[0] != 200)
return false;
$_coords['lat'] = $_result_parts[2];
$_coords['lon'] = $_result_parts[3];
}
break;[/php:1:406853f338] |
|
Back to top |
|
hemmeter Smarty Rookie
Joined: 23 Aug 2006 Posts: 12 Location: California
|
Posted: Thu Aug 31, 2006 3:00 pm Post subject: |
|
|
Excellent! Thanks. Do you think it's safe to assume that Google's documented API will not cause me the issue I had before? AS long as I stay within the rate limit, that is. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Aug 31, 2006 3:19 pm Post subject: |
|
|
I would think it should work fine. |
|
Back to top |
|
|