Google map latitude php problem.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Google map latitude php problem.

Post by Citizen »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I've created a google map that maps my users by IP address. I query hostip.info to get their geolocation but the problem is some of the results come back empty and hostip.info takes awhile to return the empty results.

I've done some research about sockets but I'm not sure how I would use it or even if I should.

Keep in mind that this code gives succesful results sometimes, but takes too long to time out if the results come back empty.

Anywho, here's my code inside my loop that provides the latitude and longitude for my map:

Code: Select all

$results[$i]=file_get_contents("http://www.hostip.info/api/get.html?ip=$ip&position=true");
		preg_match('/Latitude: (.*)/', $results[$i], $lat);
		preg_match('/Longitude: (.*)/', $results[$i], $lon);
Any ideas?


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
iluxa
Forum Newbie
Posts: 15
Joined: Wed Nov 29, 2006 3:29 am

Post by iluxa »

As far as timeouts, you can use CURL instead of file_get_contents(), which allows you great deal of control over what and how is requested.
You _will_ get empty/incorrect results though, since hostip.info database is really incomplete
(i.e. according to the site I leave right in the middle of the San Francisco bay :)
Post Reply