我遇到了一些奇怪的事情,我的自定義Google地圖在手機或平板電腦上不可見。但在桌面上,它工作正常。我無法解決問題。在移動設備和平板電腦上不顯示自定義Google地圖
我的HTML如下:
<div class="wrapper">
<div id="maps-canvas"></div>
<div class="clearfix"></div>
</div>
而且我的自定義JS:
$(window).bind("load", function() {
if ($('#maps-canvas').length) {
CustomGoogleMaps();
}
});
function CustomGoogleMaps() {
// Creating a LatLng object containing the coordinate for the center of the map
var latlng = new google.maps.LatLng(52.145022, 5.422421);
var map = new google.maps.Map(document.getElementById('maps-canvas'), {
//options
zoom: 18, // This number can be set to define the initial zoom level of the map
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP, // This value can be set to define the map type ROADMAP/SATELLITE/HYBRID/TERRAIN
zoomControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.SMALL,
position: google.maps.ControlPosition.LEFT_BOTTOM
},
scaleControl: true,
streetViewControl: true,
streetViewControlOptions: {
position: google.maps.ControlPosition.LEFT_BOTTOM
}
});
// Detect the resize event and keep marker in center when on resize
google.maps.event.addDomListener(window, "resize", function() {
var center = map.getCenter();
google.maps.event.trigger(map, "resize");
map.setCenter(center);
});
// Define Marker properties
var imagePath = "http://google-maps-icons.googlecode.com/files/sailboat-tourism.png";
var image = new google.maps.MarkerImage(imagePath,
// This marker is 75 pixels wide by 101 pixels tall.
new google.maps.Size(75, 101),
// The origin for this image is 0,0.
new google.maps.Point(0, 0),
// The anchor for this image is the base of the flagpole at 18,101.
new google.maps.Point(18, 101)
);
// Add Marker
var marker1 = new google.maps.Marker({
position: new google.maps.LatLng(52.145022, 5.422421),
map: map,
icon: image, // This path is the custom pin to be shown. Remove this line and the proceeding comma to use default pin
animation: google.maps.Animation.DROP, // Animate drop effect of the marker
position: latlng // The position should be the latlng coordinates
});
// Add listener for a click on the pin
google.maps.event.addListener(marker1, 'click', function() {
infowindow1.open(map, marker1);
});
// Add information window
//change address details here
var contentString = '<div class="map-info-box">'
+ '<div class="map-head">'
+ '<h3>Company Title</h3></div>'
+ '<p class="map-address">My Address</p>';
var infowindow1 = new google.maps.InfoWindow({
content: contentString,
});
// Create information window
function createInfo(title, content) {
return '<div class="maps-info-window"><strong>' + title + '</strong><br />' + content + '</div>';
}
}
希望有人能幫助我走上正確的道路。
雖然,我的示例是遵循「揭示模塊模式」。我想爲你的目的一個更簡單的方法,只是將你的CustomGoogleMaps函數作爲回調傳遞給谷歌地圖腳本。 –
非常感謝您的努力,但它仍然無法正常工作。你有可能改變我的小提琴嗎? – Ramirez