4
A
回答
0
使用Geocoder類。這並不難,然後你可以使用getFromLocationName
,它可以做你想做的。您也可以反過來使用這個類,也就是說,輸入(lat,lon)並獲取位於那裏的地址。
我假設你想通過Android代碼來實現,如果你想使用Javascript,那麼你應該使用Google map's API,正如另一個答案中指出的那樣。
3
searchesAddress - >可以是(城市名稱/地址/郵編)。
public boolean getLatitudeAndLongitudeFromGoogleMapForAddress(String searchedAddress){
Geocoder coder = new Geocoder(IPlant.iPlantActivity);
List<Address> address;
try
{
address = coder.getFromLocationName(searchedAddress,5);
if (address == null) {
Log.d(TAG, "############Address not correct #########");
}
Address location = address.get(0);
Log.d(TAG, "Address Latitude : "+ location.getLatitude();+ "Address Longitude : "+ location.getLongitude());
return true;
}
catch(Exception e)
{
Log.d(TAG, "MY_ERROR : ############Address Not Found");
return false;
}
}
4
通過網
private static JSONObject getLocationInfo(String address)
{
StringBuilder stringBuilder = new StringBuilder();
try {
address = address.replaceAll(" ","%20");
HttpPost httppost = new HttpPost("http://maps.google.com/maps/api/geocode/json?address=" + address + "&sensor=false");
HttpClient client = new DefaultHttpClient();
HttpResponse response;
stringBuilder = new StringBuilder();
response = client.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream stream = entity.getContent();
int b;
while ((b = stream.read()) != -1) {
stringBuilder.append((char) b);
}
} catch (ClientProtocolException e) {
Log.i("getLocationInfo ClientProtocolException", e.toString());
} catch (IOException e) {
Log.i("getLocationInfo IOException", e.toString());
}
JSONObject jsonObject = new JSONObject();
try {
jsonObject = new JSONObject(stringBuilder.toString());
} catch (JSONException e) {
// TODO Auto-generated catch block
Log.i("getLocationInfo JSONException", e.toString());
}
return jsonObject;
}
private static boolean getLatLong(JSONObject jsonObject)
{
try {
longitute = ((JSONArray)jsonObject.get("results")).getJSONObject(0).getJSONObject("geometry").getJSONObject("location").getDouble("lng");
Log.i("Log1", longitute1+"");
latitude = ((JSONArray)jsonObject.get("results")).getJSONObject(0)
.getJSONObject("geometry").getJSONObject("location")
.getDouble("lat");
Log.i("lat1", latitude1+"");
} catch (JSONException e) {
longitute=0;
latitude = 0;
Log.i("getLatLong", e.toString());
return false;
}
return true;
}
獲得地理座標
相關問題
- 1. 從經緯度獲取城市名稱
- 2. 如何從城市名稱獲取經度,緯度android代碼
- 3. 谷歌地圖獲取有城市名稱的經緯度?
- 4. 如何獲取城市的經緯度?
- 5. 如何從GWT的MapVisualization的城市名稱獲取緯度/經度?
- 6. 從給定的城市名稱獲取經度和緯度的簡單API
- 7. 從特定語言的緯度,經度獲取城市名稱javascript api
- 8. 如何從經度和緯度得到城市名稱?
- 9. 從lang緯度獲取城市名稱,android
- 10. 我想獲得城市名稱的經緯度
- 11. OSM - 提取街道名稱,經緯度和城市
- 12. 如何從電話差距的經緯度中獲取城市名稱?
- 13. 從經緯度得到國家,地區和城市名稱(PHP)
- 14. 如何從城市名稱中查找經緯度
- 15. 是否可以從經度/緯度獲取城市?
- 16. 如何使用緯度和經度獲取位置名稱或城市?
- 17. 獲取基於城市,郵編或街道名稱的經度和緯度
- 18. 緯度和經度放置在.NET中的名稱或城市
- 19. 使用經度和緯度查找城市和州名稱
- 20. 過濾城市的經緯度與其他城市的距離(經緯度)?
- 21. 從經緯度獲取位置名稱
- 22. 從Google表格的經緯度獲取城市,州和國家
- 23. 從經緯度獲取城市,州,國家
- 24. 如何獲取城市/國家名稱的經緯度範圍android
- 25. 使用HTML獲取城市名稱的經緯度,bing地圖中的js
- 26. Android經緯度與GPS或城市名稱
- 27. 如何在JavaScript中找到經緯度的城市名稱?
- 28. 按城市或經度和緯度
- 29. 如何根據緯度和經度獲取城市?
- 30. 獲取特定城市的緯度和經度android