在执行脚本的第169行时,我转到第182行。
可能是什么问题呢 ?
最佳答案
我在onload函数中使用此函数initMap对我有用,希望对您有帮助
function initMap() {
map = new google.maps.Map(document.getElementById('mapSection'), {
center: { lat: 13.0480787, lng: 79.9288088 },
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoomControl: true,
zoomControlOptions: {
position: google.maps.ControlPosition.LEFT_CENTER
},
});
// Create the search box and link it to the UI element.
var input = document.getElementById('pac-input');
var searchBox = new google.maps.places.SearchBox(input);
map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
// Bias the SearchBox results towards current map's viewport.
map.addListener('bounds_changed', function() {
searchBox.setBounds(map.getBounds());
var bounds = map.getBounds();
});
var markers = [];
var geocoder = new google.maps.Geocoder();
searchBox.addListener('places_changed', function() {
var places = searchBox.getPlaces();
if (places.length == 0) {
return;
}
geocodeAddress(geocoder, map);
// Clear out the old markers.
markers.forEach(function(marker) {
marker.setMap(null);
});
markers = [];
// For each place, get the icon, name and location.
var bounds = new google.maps.LatLngBounds();
map.fitBounds(bounds);
});
// [END region_getplaces]
function geocodeAddress(geocoder, resultsMap) {
var address = document.getElementById('pac-input').value;
geocoder.geocode({'address': address}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
}
如果您想在地图上使用标记,请使用此功能
function create_Marker(lat, lan, drivername, indx) {
var MARKER = new google.maps.Marker({
position : new google.maps.LatLng(lat, lan),
map : MAP,
icon : "images/car.png",
title : drivername,
animation : google.maps.Animation.DROP
});
MARKER_List.push(MARKER);
google.maps.event.addListener(MARKER, 'click', (function(marker, indx) {
return function() {
infowindow.setContent("<div class='content' style='max-height:300px; font-size:12px;';'>" + drivername
+ "</div>");
infowindow.open(MAP, marker);
}
})(MARKER, indx));
}