Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

addMarkerByAddress not responding in GoogleMapAPI

 
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons
View previous topic :: View next topic  
Author Message
hemmeter
Smarty Rookie


Joined: 23 Aug 2006
Posts: 12
Location: California

PostPosted: Sun Aug 27, 2006 3:00 am    Post subject: addMarkerByAddress not responding in GoogleMapAPI Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7361
Location: Lincoln Nebraska, USA

PostPosted: Mon Aug 28, 2006 2:57 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
hemmeter
Smarty Rookie


Joined: 23 Aug 2006
Posts: 12
Location: California

PostPosted: Wed Aug 30, 2006 7:31 pm    Post subject: Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7361
Location: Lincoln Nebraska, USA

PostPosted: Wed Aug 30, 2006 8:43 pm    Post subject: Reply with quote

Do you have a sample address? It is working fine for me.
Back to top
View user's profile Send private message Visit poster's website
hemmeter
Smarty Rookie


Joined: 23 Aug 2006
Posts: 12
Location: California

PostPosted: Wed Aug 30, 2006 8:54 pm    Post subject: Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7361
Location: Lincoln Nebraska, USA

PostPosted: Wed Aug 30, 2006 9:05 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7361
Location: Lincoln Nebraska, USA

PostPosted: Wed Aug 30, 2006 9:08 pm    Post subject: Reply with quote

I just now realized, Google has an API:

http://www.google.com/apis/maps/documentation/#Geocoding_HTTP_Request

and GoogleMapAPI is not using this. I'll see if I can integrate this.
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7361
Location: Lincoln Nebraska, USA

PostPosted: Wed Aug 30, 2006 9:21 pm    Post subject: Reply with quote

Please grab the latest CVS, see if this lookup works any better.
Back to top
View user's profile Send private message Visit poster's website
hemmeter
Smarty Rookie


Joined: 23 Aug 2006
Posts: 12
Location: California

PostPosted: Wed Aug 30, 2006 9:44 pm    Post subject: Reply with quote

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
View user's profile Send private message
hemmeter
Smarty Rookie


Joined: 23 Aug 2006
Posts: 12
Location: California

PostPosted: Thu Aug 31, 2006 12:08 am    Post subject: Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7361
Location: Lincoln Nebraska, USA

PostPosted: Thu Aug 31, 2006 12:16 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
hemmeter
Smarty Rookie


Joined: 23 Aug 2006
Posts: 12
Location: California

PostPosted: Thu Aug 31, 2006 3:00 pm    Post subject: Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7361
Location: Lincoln Nebraska, USA

PostPosted: Thu Aug 31, 2006 3:19 pm    Post subject: Reply with quote

I would think it should work fine.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP