How do I get the city and country names from the output of FindGeoLocation[] {lat, long} ?
Asked
Active
Viewed 1,273 times
3
J. M.'s missing motivation
- 124,525
- 11
- 401
- 574
ged1182
- 31
- 2
3 Answers
2
One way is to do this:
nc = Nearest[
CityData[#, "Coordinates"] -> # & /@
CityData[{All, "United Kingdom"}]];
Then use this as:
nc[FindGeoLocation[]]
{{"London", "GreaterLondon", "UnitedKingdom"}}
cormullion
- 24,243
- 4
- 64
- 133
2
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

1
Starting from Mathematica version 10.0 there is GeoIdentify function
GeoIdentify["Country", GeoPosition[{-11.00505177, -76.41350033}]]
Which results in
{Entity["Country", "Peru"]}
Mykyta Kozlov
- 111
- 3
-
Of course you don't want to simply reproduce the Wolfram documentation, but it's worth pointing out that the first argument to
GeoIdentifycan be any one of a number of different kinds of entity, including "City". – High Performance Mark Oct 21 '22 at 10:25
nearLC) to find two nearest big cities (of population over 100000) for every geo-location point. – Artes Jun 17 '13 at 21:38