android - getfromLocation 返回海洋或海洋名称

标签 android google-maps location

我正在 Android 中开发反向地理编码功能。 例如,当我使用 Google API 调用中的地理编码器类执行 getFromLocation(0, 0, 1) 时,它会返回 ZERO RESULTS 并且地址长度为零。 但例如,当我访问网络上的 Google map 并右键单击位置 0,0 时,它会显示“大西洋”。当我在 Android 中的 Google map 应用中放置图钉时,此方法也有效。

有没有办法以编程方式从坐标 0,0 获取“大西洋”或类似的内容?当我说 0,0 时,它也适用于海中央的其他坐标。

最佳答案

是的,有办法获取坐标对应的海域名称。我所做的是使用 Google Maps Javascript API,然后根据请求我添加了 result_type=natural_feature ,它代表地址类型中的水体和沙漠。添加此项将返回坐标中最近的水体。 Javascript 可以使用 Webview 集成到 Android 上。

以下是我的请求以及对我的两个请求的响应:

第一个请求类似于 getFromLocation(0,0,1)

请求:

https://maps.googleapis.com/maps/api/geocode/json?latlng=0,0&key=YOUR_API_KEY

回应:

{
   "results" : [],
   "status" : "ZERO_RESULTS"
}

对于使用natural_feature的下一个请求。

请求:

https://maps.googleapis.com/maps/api/geocode/json?latlng=0,0&result_type=natural_feature&key=YOUR_API_KEY

回应:

{
   "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"
}

关于android - getfromLocation 返回海洋或海洋名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34293677/

相关文章:

javascript - 在 Google map javascript API 上画线

android - 将 Google map 缩放到当前位置

android - (再次中断)SDK还没有初始化,确保先调用FacebookSdk.sdkInitialize()。 (安卓)

android - Android 中的全局触摸手势?

java - 为什么Android使用Java概念而不是D语言或C或C++?但是 Chromium 网络浏览器是 C++ 的,它的匹配非常复杂

java - 如何在android中每1分钟移动一次获得不同的纬度和经度?

Angular - 使用后退导航测试路由

android - 应用程序 AChartengine 意外停止。请再试一次

google-maps - 在没有谷歌地图的情况下使用纬度/经度信息自动生成屏幕截图?

objective-c - -[GMSMapView animateToCameraPosition :]: unrecognized selector sent to instance