IP range to X city

  • Ads

IP range to X city

Postby Valleriani » Tue May 18, 2010 7:23 am

Right now I'm just doing tests but I have a basic system working where if you input an IP you will get the resulting information to that IP.

However, I want IPs 50KM and less depending on city/etc. I'm not sure if this is possible with this database or someone can give me a good push to the direction I should be going.

Basicly, lets say I pick Ontario, Toronto, Canada as a main city I want to get ips from or around. I can get ips that ARE from Toronto very easily, but lets say theres some ips just outside of Toronto, lets say, 20KM away, which would still be good to get on my list, but won't be picked up because there not in Toronto. Is there any way to achieve this easily?
Valleriani
 
Posts: 1
Joined: Tue May 18, 2010 7:16 am

Re: IP range to X city

Postby marchost » Sun May 23, 2010 8:24 am

Hi, it would be possible but you need indexes on the latitude and longitude :

SELECT *, (DEGREES(acos(sin(RADIANS(YOURLATITUDE)) * sin(RADIANS(`latitude`)) + cos(RADIANS(YOURLATITUDE)) * cos(RADIANS(`latitude`)) * cos(RADIANS(YOURLONGITUDE - `longitude`)))) * 60 * 1.1515 * 1.609344) as distance FROM `ip_group_city` WHERE distance <= 50

I didnt test the query but it should work. Dont forget to modify YOURLATITUDE, YOURLONGITUDE with the center coordinates

Marc
marchost
Site Admin
 
Posts: 374
Joined: Wed Apr 08, 2009 9:55 pm


Return to IP geolocation API related



Who is online

Users browsing this forum: No registered users and 1 guest