获取GPS地图的GPS坐标
答
我建议你看一下Google Maps V3 API的Geocoder部分。我自己只是经历了这个问题。当建立表单,包括隐藏输入lat和长(无论在你的数据库的字段名)是这样的:
<input type="hidden" name="data[Location][lat]" id="LocationLat"/>
<input type="hidden" name="data[Location][lon]" id="LocationLon"/>
在您的地址输入,你会说这样的事情:
<input name="data[Location][address]" onChange="getLatLong(address)" size="50" maxlength="255" type="text"/>
您可以在其中包含对称为getLatLong()的JavaScript函数的调用。
这里是下面的函数的例子:
<script type="text/javascript" >
var geocoder;
var add = document.getElementById("LocationAddress");
function getLatLong(address){
geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address':address},function(results, status){
if (status == google.maps.GeocoderStatus.OK) {
document.getElementById("LocationLat").value=results[0].geometry.location.lat();
document.getElementById("LocationLon").value=results[0].geometry.location.lng();
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
</script>
您可能需要摆弄它一下。一定要在这里搜索谷歌地理编码器,因为我发现我的解决方案与我从这个网站直接得到的零件。
确切的坐标是什么?...左上角,中心等。? – Engineer 2012-03-16 20:08:22
你能更清楚地陈述这个问题吗?你是否接受用户输入的坐标?或者你想确定用户的坐标? – 2012-03-16 20:08:42
我zqnt用户点击地图和坐标到形式 – ziz194 2012-03-17 01:13:45