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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745042646a4607903.html
评论列表(0条)