0x_Anakin
0x_Anakin

Reputation: 3269

Getting best latitude longitude response form various ip database internet services

I have a website that checks the users ip address on many online databases, and gets responses with latitude and longitude.

Here is an example:

Array
(
    [0] => stdClass Object
        (
            [statusCode] => OK
            [statusMessage] => 
            [ipAddress] => 37.6.226.186
            [countryCode] => GR
            [countryName] => GREECE
            [regionName] => ATTIKI
            [cityName] => ATHENS
            [zipCode] => -
            [latitude] => 37.9795
            [longitude] => 23.7162
            [timeZone] => +03:00
        )

    [1] => stdClass Object
        (
            [ip] => 37.6.226.186
            [country_code] => GR
            [country_name] => Greece
            [region_code] => 
            [region_name] => 
            [city] => 
            [zipcode] => 
            [latitude] => 39
            [longitude] => 22
            [metro_code] => 
            [areacode] => 
        )

    [2] => stdClass Object
        (
            [source] => smart-ip.net
            [host] => 37.6.226.186
            [lang] => en
            [countryName] => Greece
            [countryCode] => GR
            [city] => 
            [region] => 
            [latitude] => 39.0000
            [longitude] => 22.0000
            [timezone] => 
        )

)

I have noticed that sometimes 1 response might be totally off showing an irrelevant place hence a bad latitude + longitude.

How would you resolve an issue as this? perhaps loop through the results and check closest values and then pick 1 response? I'm not sure about this since I'm junior in php. Any guidance or reference will be greatly appreciated.

Upvotes: 0

Views: 316

Answers (1)

Oswald
Oswald

Reputation: 31657

There is no way for you to determine which coordinates are the best. Any value might be correct, even the one that seems to be irrelevant. More likely, none of the values is correct.

If you want to pick a value, pick one at random. It's as good as any other.

The other option is to apply some algorithm to all the values (e.g. the average of the ones in the city with the most records or the average of the ones where the most records fall into a 10 mile radius).

Upvotes: 1

Related Questions