Reputation: 190
I am working on a reverse geo-coding functionality in Android.
When I do a getFromLocation(0, 0, 1)
using the geocoder class from Google API call for example it returns ZERO RESULTS
and the address length is zero.
But for example when I go to Google Maps on the web and I right click on location 0,0 it says "Atlantic Ocean". This also work when I drop a pin in the Google Maps App in Android.
Is there a way to get "Atlantic Ocean" or similar programatically from the coordinates 0,0 ? When I say 0,0 it also applies to other coordinates that are in the middle of the sea.
Upvotes: 2
Views: 1296
Reputation: 1454
Yes, there is a way to get the name of the sea corresponding to the coordinates. What I did is to use Google Maps Javascript API then on the request I've added the result_type=natural_feature which represents bodies of water and deserts in the address type. Adding this will return the nearest body of water in the coordinates. Javascript can be integrated on android using a Webview.
Here are my requests and responses for my two requests:
This first request is similar to getFromLocation(0,0,1)
Request:
https://maps.googleapis.com/maps/api/geocode/json?latlng=0,0&key=YOUR_API_KEY
Response:
{
"results" : [],
"status" : "ZERO_RESULTS"
}
For this next request which uses natural_feature.
Request:
Response:
{
"results" : [
{
"address_components" : [
{
"long_name" : "Atlantic Ocean",
"short_name" : "Atlantic Ocean",
"types" : [ "natural_feature", "establishment" ]
}
],
"formatted_address" : "Atlantic Ocean",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 68.6187515,
"lng" : 20
},
"southwest" : {
"lat" : -83.0204773,
"lng" : -83.21609509999999
}
},
"location" : {
"lat" : -14.5994134,
"lng" : -28.6731465
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 68.6187515,
"lng" : 20.0000001
},
"southwest" : {
"lat" : -83.0204773,
"lng" : -83.21609509999999
}
}
},
"place_id" : "ChIJ_7hu48qBWgYRT1MQ81ciNKY",
"types" : [ "natural_feature", "establishment" ]
},
{
"address_components" : [
{
"long_name" : "Equator",
"short_name" : "Equator",
"types" : []
}
],
"formatted_address" : "Equator",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 0,
"lng" : 180
},
"southwest" : {
"lat" : 0,
"lng" : -180
}
},
"location" : {
"lat" : 0,
"lng" : 0
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 0.00134898029150203,
"lng" : 180
},
"southwest" : {
"lat" : -0.00134898029150203,
"lng" : -180
}
}
},
"place_id" : "ChIJ9f-dgJ14AHARMp45pd8HMhs",
"types" : []
},
{
"address_components" : [
{
"long_name" : "Virgo",
"short_name" : "Virgo",
"types" : []
}
],
"formatted_address" : "Virgo",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 14.3954258,
"lng" : 47.853012
},
"southwest" : {
"lat" : -22.9842321,
"lng" : -5.6577015
}
},
"location" : {
"lat" : -4.294403099999999,
"lng" : 21.0976553
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 14.3954258,
"lng" : 47.853012
},
"southwest" : {
"lat" : -22.9842321,
"lng" : -5.6577015
}
}
},
"place_id" : "ChIJ3dT5sNUyHxoRJjQnMK1jABU",
"types" : []
}
],
"status" : "OK"
}
Upvotes: 2