【发布时间】:2022-01-09 12:18:10
【问题描述】:
我有一个显示谷歌地图的简单网站。我的问题是,现在它从纽约开始,我希望它从伦敦开始。我该怎么做?
在我的 HTML 页面中
<script src="https://maps.googleapis.com/maps/api/js?key=MY_API_KEY;callback=initMap" async defer></script>
``
和
<div id="map" class="map height-400"></div>
我相信这是它使用的 java 脚本 -
"use strict";
This is the gmap.js I am using which I believe picks the location.
window.initMap = function() {
var customMapType = new google.maps.StyledMapType([
{
stylers: [
{'saturation': -100},
{'lightness': 50},
{'visibility': 'simplified'}
]
},
{
elementType: 'labels',
stylers: [{visibility: 'on'}]
},
{
featureType: 'road',
stylers: [{color: '#bbb'}]
}
], {
name: 'Dublin'
});
var image = new google.maps.MarkerImage(
'img/widgets/gmap-pin.png',
new google.maps.Size(48,54),
new google.maps.Point(0,0),
new google.maps.Point(24,54)
);
var customMapTypeId = 'custom_style';
var brooklyn = {lat: 41.850, lng: -73.961};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 6,
scrollwheel: false,
streetViewControl: false,
mapTypeControl: false,
center: London,
mapTypeControlOptions: {
mapTypeIds: [google.maps.MapTypeId.ROADMAP, customMapTypeId]
}
});
var contentString = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h1 id="firstHeading" class="firstHeading">Brooklyn</h1>'+
'<div id="bodyContent">'+
'<p>277 Bedford Avenue, <br> Brooklyn, NY 11211, <br> New York, USA</p>'+
'</div>'+
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString,
maxWidth: 300
});
var marker = new google.maps.Marker({
map: map,
clickable: true,
icon: image,
title: 'Brooklyn',
position: brooklyn
});
marker.addListener('click', function() {
infowindow.open(map, marker);
});
map.mapTypes.set(customMapTypeId, customMapType);
map.setMapTypeId(customMapTypeId);
}
整个 API 和流程对我来说是非常新的,如果有人有答案,我将不胜感激!太棒了!
【问题讨论】:
-
MarkerImage已弃用,并已从文档中删除,请改用匿名Icon接口(可能不是问题),minimal reproducible example 可以证明您的问题,最好是工作 @987654322重现您的问题的@会有所帮助。您是否收到任何 JavaScript 错误?
标签: javascript html google-maps web google-maps-api-3