admin管理员组文章数量:1410705
The following code throw exception as titled in firefox.
<script type="text/javascript">
$(function () {
initialize();
});
var geocoder;
function initialize() {
geocoder = new google.maps.Geocoder();
}
The following code throw exception as titled in firefox.
<script type="text/javascript">
$(function () {
initialize();
});
var geocoder;
function initialize() {
geocoder = new google.maps.Geocoder();
}
Share
Improve this question
edited Feb 27, 2013 at 9:40
Thomas
2,7775 gold badges32 silver badges52 bronze badges
asked Feb 27, 2013 at 9:21
user2114637user2114637
211 gold badge1 silver badge2 bronze badges
5 Answers
Reset to default 1My guess is that you didn't include Google Map's header, because your code seems correct.
Try following the steps here.
With the newest way to import a library, the geocoder()
method may not be in the maps
anymore.
Let say you have the following
const promises = [
mapLoader.importLibrary('maps'),
mapLoader.importLibrary('geocoding'),
]
// Use Promise.all() to send the promises in parallel
return Promise.all(promises)
.then(([maps, geocoding, places, core]) => {
// Return the results as a single object named 'google'
return {
maps,
geocoding,
}
})
.catch((error) => {})
Then it will be geocoder = new google.geocoding.Geocoder();
You should call the constructor after the body has been loaded. document.body.addEventListener('load', initialize)
add this before calling functions that consists of geocoder to ensure the specific constructor is intialized.
google.maps.importLibrary("geocoding").then(() => {
//Call your function here
}
If google map script is not loeaded, and you call map related function then you would get this kind of errors.
本文标签: javascriptGoogle TypeError googlemapsGeocoder is not a constructorStack Overflow
版权声明:本文标题:javascript - Google: TypeError: google.maps.Geocoder is not a constructor - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745042646a2639170.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论