问题描述
我对google.maps.geometry.poly.isLocationOnEdge()方法有问题。在小提琴中,尝试点击水平线,像预期的那样返回true,但点击垂直线返回false。为什么?
谢谢!
这里是,这里是代码:
function initialize(){
var mapOptions = {
zoom:8,
center:new google.maps.LatLng(0.5,0.5),
mapTypeId:google.maps.MapTypeId.TERRAIN
};
var map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
var poly = new google.maps.Polyline({
path:[
new google.maps.LatLng(0,0),
new google.maps .LatLng(0,1),
new google.maps.LatLng(1,1)
],
map:map
});
google.maps.event.addListener(poly,'click',function(event){
alert(google.maps.geometry.poly.isLocationOnEdge(event.latLng,this), 0.00001);
});
}
google.maps.event.addDomListener(window,'load',initialize);
我认为您最好使用 containsLocation()
从:
vs p>
如果您使用 containsLocation
它可以工作
alert(google.maps.geometry.poly.containsLocation(event.latLng,poly));
分叉小提琴
我真的无法解释为什么它不能与 isLocationOnEdge
。这似乎是 100%垂直多段线的一个问题,并且对于您的0,0,0,1等,Lng始终为零(0)(单击垂直) - 就好像线不有任何宽度,地图。
I have a problem with google.maps.geometry.poly.isLocationOnEdge() method. In fiddle, try to click on horizontal line, returns true like expected, but clicking on vertical line returns false. Why?
Thanks!
Here is fiddle and here is code:
function initialize() {
var mapOptions = {
zoom: 8,
center: new google.maps.LatLng(0.5, 0.5),
mapTypeId: google.maps.MapTypeId.TERRAIN
};
var map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
var poly = new google.maps.Polyline({
path: [
new google.maps.LatLng(0, 0),
new google.maps.LatLng(0, 1),
new google.maps.LatLng(1, 1)
],
map: map
});
google.maps.event.addListener(poly, 'click', function(event){
alert(google.maps.geometry.poly.isLocationOnEdge(event.latLng, this), 0.00001);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
I think you are better off using containsLocation()
From the docs :
vs
If you use containsLocation
it works
alert(google.maps.geometry.poly.containsLocation(event.latLng, poly));
forked fiddle http://jsfiddle.net/VL7Rx/
I really cant explain exactly why it does not working with isLocationOnEdge
. It seems to be an issue on 100% vertical polylines only, and with your 0,0,0,1 etc the Lng always is zero (0) (clicking vertical) - as if the line does not have any "width" at all, "mapwise".
这篇关于Google地图API V3 - isLocationOnEdge()不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!