Wenn ich die Seite laden, die meine Google Maps angezeigt wird, ich folgende Fehlermeldung in der Konsole immer sehen:Google Maps - Uncaught InvalidValueError: Initialisierung ist keine Funktion
Uncaught InvalidValueError: initialise is not a function js?sensor=false&callback=initialise:94
Wenn über den Dateinamen schweben, diese zeigt sich als von https://maps.googleapis.com/maps/api/js?sensor=false&callback=initialise
Das Google Maps-Fenster und Karte zeigt jedoch absolut gut und hat die volle Funktionalität. Seltsamerweise konnte ich diesbezüglich keine Treffer bei Google finden, sie scheinen alle über setLong und setLat zu sein. Wenn ich die Reihenfolge des Ladens zwischen dem API-Aufruf und der JS-Datei ändere, ändert sich die Fehlermeldung zwischen initialise
und google
. In beiden Fällen wird die Karte jedoch weiterhin ordnungsgemäß geladen.
Warum tritt der Fehler auf und wie kann ich den Fehler beheben? Hier ist meine Google-map.js Datei:
function initialise() {
var myLatlng = new google.maps.LatLng(51.126500, 0.257595); // Add the coordinates
var mapOptions = {
zoom: 15, // The initial zoom level when your map loads (0-20)
disableDefaultUI: true, // Disable the map UI
center: myLatlng, // Centre the Map to our coordinates variable
mapTypeId: google.maps.MapTypeId.ROADMAP, // Set the type of Map
scrollwheel: false, // Disable Mouse Scroll zooming (Essential for responsive sites!)
// All of the below are set to true by default, so simply remove if set to true:
panControl:false, // Set to false to disable
mapTypeControl:false, // Disable Map/Satellite switch
scaleControl:false, // Set to false to hide scale
streetViewControl:false, // Set to disable to hide street view
overviewMapControl:false, // Set to false to remove overview control
rotateControl:false // Set to false to disable rotate control
}
var map = new google.maps.Map(document.getElementById('map'), mapOptions); // Render our map within the empty div
var image = new google.maps.MarkerImage('/wp-content/themes/bellavou/img/marker2.png', null, null, null, new google.maps.Size(70,70)); // Create a variable for our marker image.
var marker = new google.maps.Marker({ // Set the marker
position: new google.maps.LatLng(51.125887, 0.258075), // Position marker to coordinates
icon:image, //use our image as the marker
map: map, // assign the market to our map variable
title: 'Bella Vou at The Pantiles' // Marker ALT Text
});
}
google.maps.event.addDomListener(window, 'load', initialise); // Execute our 'initialise' function once the page has loaded.
Ohne Ihren Code zu veröffentlichen, wie können wir möglicherweise helfen? – MrUpsidown
Nicht sicher, dass Sie es brauchen, aber okay, ich poste es ... – Lee
Zuerst definieren Sie einen Rückruf auf den API-Aufruf 'https://maps.googleapis.com/maps/api/js?sensor=false&callback=initialise 'Dann fügst du einen Listener' google.maps.event.addDomListener (window, 'load', initialisiere); 'das macht im Grunde dasselbe. Entfernen Sie diese Listener-Zeile oder entfernen Sie den Callback = initialise vom API-Aufruf und teilen Sie uns mit, ob es besser funktioniert. – MrUpsidown