I have a simple php function which get's the closest nearby city from a given latitude and longitude:
function findCity($lat, $lng, $username) {
$json_url = "http://api.geonames.org/findNearbyPlaceNameJSON?lat=" . $lat . "&lng=" . $lng . "&username=" . $username;
$json = file_get_contents($json_url);
$json = str_replace('},
]', "}
]", $json);
$data = json_decode($json);
echo "<pre>";
print_r($data);
echo "</pre>";
}
This method returns the following with lat: 51.992 and long: 4.89
stdClass Object
(
[geonames] => Array
(
[0] => stdClass Object
(
[countryName] => Netherlands
[adminCode1] => 11
[fclName] => city, village,...
[countryCode] => NL
[lng] => 4.876389
[fcodeName] => populated place
[distance] => 1.42349
[toponymName] => Langerak
[fcl] => P
[name] => Langerak
[fcode] => PPL
[geonameId] => 2751924
[lat] => 51.931667
[adminName1] => South Holland
[population] => 0
)
)
)
This returns the closest city, but I am looking for something like this. Where only the closest large city is returned. Is this possible? Or are there other alternatives to solve this. I've read about the Google Geocoding API, but we can't use it since we aren't using a Google map to show the results. (Note: the Geocoding API may only be used in conjunction with a Google map; geocoding results without displaying them on a map is prohibited. Source)
I know this isn't an actual programmer problem, but since the geonames forums are not really active, I figured I would post it here.