2015-12-15 49 views
2

我正在研究Android中的反向地理編碼功能。 當我使用谷歌從API調用例如地理編碼器類做getFromLocation(0, 0, 1)返回ZERO RESULTS和地址長度爲零。 但是,例如,當我訪問網絡上的Google地圖時,右鍵單擊位置0,0,它會顯示「大西洋」。當我在Android的谷歌地圖應用程序中放置圖釘時,這也同樣適用。getfromLocation返回海洋或海域名稱

有沒有辦法從座標0,0得到「大西洋」或類似的編程?當我說0,0時,它也適用於位於海中的其他座標。

回答

1

是的,有一種方式來獲得對應的座標海的名字。我所做的就是使用Google Maps JavaScript API,然後根據請求添加result_type = natural_feature,它代表地址類型中的水體和沙漠體。添加這個將返回座標中最近的水體。使用Webview可以將Javascript集成到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" 
} 
+0

感謝您的回答。我通過JSON解釋器工作。我不得不使用AsyncTask來完成http請求。謝謝!! :) – Renato