Okay, ich hoffe, das macht Sinn. Unten ist mein Code für meine Google Map und es funktioniert großartig (nicht das sauberste, aber es funktioniert). Wie kann ich außerhalb der Karte einen HTML-Link erstellen, der die Infobox für mich öffnet? Zum Beispiel möchte ich in der Lage zu tun:Öffnen Sie die Google Maps Info Box mit dem Link
<a href="#map" onclick="openInfo(2)">More Info</a>
und das würde die Info-Box für Marker 2, die der Dienstag wäre. Hoffe, das macht Sinn.
<script>
jQuery(function($) {
// Asynchronously Load the map API
var script = document.createElement('script');
script.src = "//maps.googleapis.com/maps/api/js?sensor=true&callback=initialize&key=APIKEY";
document.body.appendChild(script);
});
var gmarkers = [];
function initialize() {
var map;
var bounds = new google.maps.LatLngBounds();
var mapOptions = {
mapTypeId: 'roadmap'
};
// Display a map on the page
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
map.setTilt(45);
// Multiple Markers
var markers = [
['1', LAT,LONG],
['2', LAT,LONG],
];
// Info Window Content
var infoWindowContent = [
['<strong>Monday - 7:00pm</strong>'],
['<strong>Tuesday - 6:00pm</strong>'],
];
// Display multiple markers on a map
var infoWindow = new google.maps.InfoWindow(), marker, i;
// Loop through our array of markers & place each one on the map
for(i = 0; i < markers.length; i++) {
var position = new google.maps.LatLng(markers[i][1], markers[i][2]);
bounds.extend(position);
marker = new google.maps.Marker({
position: position,
map: map,
title: markers[i][0]
});
// Allow each marker to have an info window
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infoWindow.setContent(infoWindowContent[i][0]);
infoWindow.open(map, marker);
}
})(marker, i));
// Automatically center the map fitting all markers on the screen
map.fitBounds(bounds);
}
// Override our map zoom level once our fitBounds function runs (Make sure it only runs once)
var boundsListener = google.maps.event.addListener((map), 'bounds_changed', function(event) {
this.setZoom(11);
google.maps.event.removeListener(boundsListener);
});
var opt = { minZoom: 9, maxZoom: 12 };
map.setOptions(opt);
}
</script>
Open Info Window Ich denke, dass dieser Beitrag Ihnen helfen wird: https://stackoverflow.com/questions/18333679/google-maps-open-info-window-after-click-on-a- -link – VA79
Das scheint nicht zu funktionieren, ich bekomme folgende Fehlermeldung: VM10743: 1 Uncaught ReferenceError: Marker ist nicht definiert –