如果用户允许使用地理位置,请有人建议我将客户端Java脚本位置变量(lat,lng)尽快传递给我的服务器端。这样,我就可以使用location变量查询数据库中10公里范围内的商店,并将它们显示在地图上。
我在客户端使用HTML5地理定位获取用户的位置,在服务器端使用Django + PostGIS数据库进行远程查找。
发布于 2013-09-04 14:52:45
为了将用户地理位置从客户端传递到服务器端,只要用户允许使用他的地理位置,就是
上述两种代码都必须在Geolocation中编写,如下所示。
var infowindow = new google.maps.InfoWindow({
map: map,
position: pos,
content: 'Location found using HTML5.'
});
// the below line has been inserted to assign a JS variable to HTML input field called 'geolocation'
document.getElementById('location').value = pos
map.setCenter(pos);
// the below line has been inserted to autosubmit the form.
document.getElementById("geolocation").submit(); 下面是HTML表单
<form id = "geolocation" action="/location" method="POST" >
{% csrf_token %}
<input type="text" id = "location" name="location" value="" />
<input type="submit" />
</form>https://stackoverflow.com/questions/18592871
复制相似问题