我正在尝试创建一个能够跟踪我的位置并同时能够显示多个标记的地图。我可以结合下面的 2 个 JavaScript 吗?如果不知道我应该怎么做?
用于多个标记的 JavaScript
<script type="text/javascript">
var locations = [
['Hougang', 1.37265, 103.893658],
['Punggol', 1.400617, 103.907833],
['MacRitchie Reservoir', 1.346002, 103.825436],
['Bishan', 1.352051, 103.849125],
['Sentosa', 1.251226, 103.830757]
];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 15,
center: new google.maps.LatLng(1.37265, 103.893658),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
google.maps.event.addListener(marker, 'click', (function (marker, i) {
return function () {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
当前位置的 JavaScript
navigator.geolocation.getCurrentPosition(function(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
}