gpt4 book ai didi

sqlite - 使用谷歌地图进行地理围栏

转载 作者:行者123 更新时间:2023-12-03 18:25:15 31 4
gpt4 key购买 nike

我试图让人们在谷歌地图上绘制一个矩形并存储 bottomLeft 和 topRight 坐标。

我知道我可以在代码上绘制一个矩形(参见:http://code.google.com/intl/nl-NL/apis/maps/documentation/javascript/reference.html#Rectangle),但是在我可以从我的数据库加载边界之前,人们需要先自己定义它:)

所以我的问题是,我怎样才能让人们在谷歌地图(API v3)上绘制一个矩形并存储bottomLeft和topRight角的坐标?

最佳答案

通过调查事件已经让它工作了。我花了很多时间来制作:)

这就是我为需要它的人所做的:

function mapsInitialize()
{
startPoint = new google.maps.LatLng(lat,lon);
options = { zoom: 16, center: startPoint, mapTypeId: google.maps.MapTypeId.HYBRID};
map = new google.maps.Map(document.getElementById("map_canvas"), options);


google.maps.event.addListener(map, 'click', function(event) {
if (drawing == true){
placeMarker(event.latLng);
if (bottomLeft == null) {
bottomLeft = new google.maps.LatLng(event.latLng.Oa, event.latLng.Pa);
}
else if (topRight == null){
topRight = new google.maps.LatLng(event.latLng.Oa, event.latLng.Pa);
drawing = false;
rectangle = new google.maps.Rectangle();

var bounds = new google.maps.LatLngBounds(bottomLeft, topRight);

var rectOptions = {
strokeColor: "#FF0000",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#FF0000",
fillOpacity: 0.35,
map: map,
bounds: bounds
};
rectangle.setOptions(rectOptions);
}
}
});
}

function placeMarker(location) {
var marker = new google.maps.Marker({
position: location,
map: map
});
}

关于sqlite - 使用谷歌地图进行地理围栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7952674/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com