-1

Below are the pairs of latitude and longitude.

Pair 1:

  • Latitude : 55.95325200
  • Longitude: -3.18826700

Pair 2:

  • Latitude : -7.09091100
  • Longitude: 107.66888700

Pair 3:

  • Latitude : 40.71278400
  • Longitude: -74.00594100

Pair 4:

  • Latitude : 52.93991600
  • Longitude: -73.54913600

Now am using geoplugin to get country code, like below.

For pair 1: http://www.geoplugin.net/extras/postalcode.gp?lat=55.95325200&long=-3.18826700

For pair 2:http://www.geoplugin.net/extras/postalcode.gp?lat=-7.09091100&long=107.66888700

For pair 3:http://www.geoplugin.net/extras/postalcode.gp?lat=40.71278400&long=-74.00594100

For pair 4:http://www.geoplugin.net/extras/postalcode.gp?lat=52.93991600&long=-73.54913600

For pair 2 and pair 4 it returns empty array like below.

 a:1:{i:0;a:0:{}}

So can someone tell me, how to get country code for pair 1 and pair 2.

Note: All latitude and longitude mentioned above are valid, and cross checked in google maps.

Mani Kandan
  • 699
  • 1
  • 10
  • 30
  • Are you sure those values are valid? Because when I put them in Google Maps they don't work – Kev_T Mar 02 '17 at 13:29
  • please check this url. https://www.google.co.in/maps/place/7%C2%B005'27.3%22S+107%C2%B040'08.0%22E/@-7.090911,107.6666983,17z/data=!3m1!4b1!4m5!3m4!1s0x0:0x0!8m2!3d-7.090911!4d107.668887 – Mani Kandan Mar 02 '17 at 13:47

1 Answers1

1

You can use the 'Latitude/Longitude to Place' Webservice from Geoplugin instead of the postal code service. See this page for more details.

For the second pair of coordinates simply head to:

http://www.geoplugin.net/extras/location.gp?lat=-7.09091100&long=107.66888700&format=json

Which returns:

{"geoplugin_place":"Cikareo","geoplugin_countryCode":"ID","geoplugin_region":"West Java","geoplugin_regionAbbreviated":"30","geoplugin_latitude":"-7.0900000","geoplugin_longitude":"107.6716700","geoplugin_distanceMiles":0.2,"geoplugin_distanceKilometers":0.32}

The country code is stored in "geoplugin_countryCode".

Michael
  • 26
  • 3
  • ya its working for those pairs, but still facing issue for this pairs. http://www.geoplugin.net/extras/location.gp?lat=34.04892800&long=-111.09373100&format=json – Mani Kandan Mar 02 '17 at 13:45
  • Geonet does state that it should be within 10 miles of a populated place, and this pair of coordinates looks outside of that range. Alternatively, you can give [Nominatim](http://wiki.openstreetmap.org/wiki/Nominatim#Reverse_Geocoding)` a go. See http://nominatim.openstreetmap.org/reverse?format=json&lat=34.5&lon=-111.09373100 – Michael Mar 02 '17 at 16:56
  • Its working fine, but after 250 calls its blocked my domain i guess. – Mani Kandan Mar 03 '17 at 09:35
  • Yes, that will be an issue with most API's. If you were considering an offline solution, or want to host your own webserver, administrative boundaries for the entire world can be downloaded [here](http://gadm.org/). Otherwise have a look at this exchange [here](http://stackoverflow.com/questions/6159074/given-the-lat-long-coordinates-how-can-we-find-out-the-city-country). Google currently gives 2,500 free calls. – Michael Mar 03 '17 at 12:38