将坐标转换为地名
问题描述:
我使用HTML5地理定位API来查找我的网站用户的经度和纬度。这有效,但现在我想在屏幕上显示“你可以在......”。所以我需要将我从Geolocation API获得的坐标转换为地名。将坐标转换为地名
我试了一下谷歌地图API,但我没有得到它的工作。
有谁知道如何做到这一点。
这是到目前为止我的代码
<script src="http://maps.google.com/maps?file=api&v=2&sensor=true&key=ABQIAAAA55ubMQxcIybj35yHYV_iGRTrPfqOlZVmBxwB40M45alaTGbn0hTaoOvTqt2CB0iR6c1SkxYmRqRvHA" type="text/javascript"></script>
<script type="text/javascript">
// When loaded go to:
initiate_geolocation();
function initiate_geolocation() {
navigator.geolocation.getCurrentPosition(handle_geolocation_query,handle_errors);
}
function handle_errors(error)
{
switch(error.code)
{
case error.PERMISSION_DENIED: document.getElementById("geo").innerHTML = "User did not share geolocation data";
break;
case error.POSITION_UNAVAILABLE: document.getElementById("geo").innerHTML = "Could not detect current position";
break;
case error.TIMEOUT: document.getElementById("geo").innerHTML = "retrieving geolocation position timed out";
break;
default: document.getElementById("geo").innerHTML = "unknown geolocation error";
break;
}
}
function handle_geolocation_query(position){
document.getElementById("geo").innerHTML = "Your coordinates are " + position.coords.latitude + ", " + position.coords.longitude;
var geoCoder = new GClientGeocoder();
geoCoder.getLocations(new GLatLng(position.coords.latitude, position.coords.longituder, true), getPositionName());
}
function getPositionName(response)
{
//
// Here I don't know what to do
//
}
</script>
感谢,
文森特
谢谢Pekka;) – Vinzcent 2010-09-04 12:17:00