admin管理员组文章数量:1023838
I am having the problem that google.maps.geometry.poly.containsLocation(latLng,polygon) does not work the first time when the page load, but it works later after I start to fire events.
Any idea of why this may be happening?
Thanks !
I am having the problem that google.maps.geometry.poly.containsLocation(latLng,polygon) does not work the first time when the page load, but it works later after I start to fire events.
Any idea of why this may be happening?
Thanks !
Share Improve this question asked Sep 12, 2013 at 15:45 Marcelo LagoMarcelo Lago 411 silver badge2 bronze badges 5- What error do you get in the JavaScript console? – Michael Geary Commented Sep 12, 2013 at 15:55
- What does your code look like? – duncan Commented Sep 12, 2013 at 16:18
- JavaScript console says: Uncaught TypeError: Cannot read property 'poly' of undefined – Marcelo Lago Commented Sep 12, 2013 at 16:49
- Sounds like the first time you call it the API hasn't loaded yet. But as you haven't provided any code, that is just a guess. – geocodezip Commented Sep 12, 2013 at 17:01
- 2 I found the source of the error ... I needed to specify "libraries=geometry" in the initial Google API call. See similar question at (stackoverflow./questions/10765667/…). Thanks for the tips ! – Marcelo Lago Commented Sep 12, 2013 at 17:06
1 Answer
Reset to default 4Main reason is at first time google api is not loaded properly and you are trying to use
var rsul = google.maps.geometry.poly.containsLocation(new google.maps.LatLng(-12.043333, -77.028333), bermudaTriangle);
so it is showing 'Cannot read property 'poly' of undefined'
so we need to use timeout to getting work on page load.
example:
setTimeout(function() {
var rsul = google.maps.geometry.poly.containsLocation(new google.maps.LatLng(-12.043333, -77.028333), bermudaTriangle);
console.log(rsul);
}, 1000);
so it is giving proper boolean value
I am having the problem that google.maps.geometry.poly.containsLocation(latLng,polygon) does not work the first time when the page load, but it works later after I start to fire events.
Any idea of why this may be happening?
Thanks !
I am having the problem that google.maps.geometry.poly.containsLocation(latLng,polygon) does not work the first time when the page load, but it works later after I start to fire events.
Any idea of why this may be happening?
Thanks !
Share Improve this question asked Sep 12, 2013 at 15:45 Marcelo LagoMarcelo Lago 411 silver badge2 bronze badges 5- What error do you get in the JavaScript console? – Michael Geary Commented Sep 12, 2013 at 15:55
- What does your code look like? – duncan Commented Sep 12, 2013 at 16:18
- JavaScript console says: Uncaught TypeError: Cannot read property 'poly' of undefined – Marcelo Lago Commented Sep 12, 2013 at 16:49
- Sounds like the first time you call it the API hasn't loaded yet. But as you haven't provided any code, that is just a guess. – geocodezip Commented Sep 12, 2013 at 17:01
- 2 I found the source of the error ... I needed to specify "libraries=geometry" in the initial Google API call. See similar question at (stackoverflow./questions/10765667/…). Thanks for the tips ! – Marcelo Lago Commented Sep 12, 2013 at 17:06
1 Answer
Reset to default 4Main reason is at first time google api is not loaded properly and you are trying to use
var rsul = google.maps.geometry.poly.containsLocation(new google.maps.LatLng(-12.043333, -77.028333), bermudaTriangle);
so it is showing 'Cannot read property 'poly' of undefined'
so we need to use timeout to getting work on page load.
example:
setTimeout(function() {
var rsul = google.maps.geometry.poly.containsLocation(new google.maps.LatLng(-12.043333, -77.028333), bermudaTriangle);
console.log(rsul);
}, 1000);
so it is giving proper boolean value
版权声明:本文标题:javascript - Google Maps API v3 - google.maps.geometry.poly.containsLocation not working the first time - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745530659a2154733.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论