【发布时间】:2012-08-21 03:39:55
【问题描述】:
我想使用谷歌地图检索并显示给定点具有固定半径的所有位置。
我设法找到了Display Location guide,还看到了许多关于使用 SQL 查询检索它的帖子。 我的数据库包含项目名称、地址(查找 alt、lon)、alt、lon 和描述。 如何使用存储的 alt, lon 仅检索其中的 alt,假设半径为 50 公里。
这是我的代码:
javascript
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(31.046051, 34.85161199999993);
var myOptions = {
zoom: 7,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
function updateCoordinates(latlng)
{
if(latlng)
{
document.getElementById('lat').value = latlng.lat();
document.getElementById('lng').value = latlng.lng();
}
}
function codeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
updateCoordinates(results[0].geometry.location);
if (marker) marker.setMap(null);
marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
draggable: true
});
google.maps.event.addListener(marker, "dragend", function() {
updateCoordinates(marker.getPosition());
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
function showPositionCoupons(sentlat, sentlon)
{
lat=sentlat;
lon=sentlon;
latlon=new google.maps.LatLng(lat, lon)
mapholder=document.getElementById('map_canvas')
var myOptions={
center:latlon,zoom:14,
mapTypeId:google.maps.MapTypeId.ROADMAP,
mapTypeControl:false,
};
map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
marker = new google.maps.Marker({position:latlon,map:map,title:"You are here!"});
}
我想我可能需要在循环中使用showPositionCoupons(),同时阅读alt和lon?
感谢您提供的任何帮助,我知道这是一个常见问题,但我无法使用现有的解决方案。
我尝试使用显示位置指南 DisplayLocations() 方法,但它对我不起作用,虽然那里显示位置的方式是完美的,只需要排除半径范围之外的位置。
【问题讨论】:
-
编辑你的帖子而不是评论! :)
标签: javascript google-maps geolocation