2
$\begingroup$

How do I get the city and country names from the output of FindGeoLocation[] {lat, long} ?

$\endgroup$
2
$\begingroup$

One way is to do this:

nc = Nearest[
  CityData[#, "Coordinates"] -> # & /@ 
     CityData[{All, "United Kingdom"}]];

Then use this as:

nc[FindGeoLocation[]]

{{"London", "GreaterLondon", "UnitedKingdom"}}

$\endgroup$
  • $\begingroup$ (I'm in the UK - your mileage might vary... :)) $\endgroup$ – cormullion Jun 17 '13 at 21:17
2
$\begingroup$

The fastest is probably with the use of the GeoNames API*:

loc = FindGeoLocation[]
i = Import[
"http://api.geonames.org/findNearby?lat=" <> ToString[loc[[1]]] <> 
"&lng=" <> ToString[loc[[2]]] <> "&username=demo", "XML"];
name = Cases[i[[2, 3, 1, 3]], XMLElement["name", _, x_] -> x]

*Idea from this post.

EDIT: another option is the use of WolframAlpha plugin in mathematica:

WolframAlpha["near cities"]
(* or *)
= near cities

wolframalpha output

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.