0
A
回答
1
我使用的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));
}
相關問題
- 1. 谷歌地圖/地點地理編碼
- 2. 地理編碼器地理編碼 - 谷歌地圖的JavaScript API
- 3. 谷歌地圖 - 反向地理編碼
- 4. 谷歌地圖地理編碼定價
- 5. 谷歌地圖地理編碼變化
- 6. 谷歌地圖地理編碼多行
- 7. 谷歌地圖api地理編碼
- 8. 地理編碼使用谷歌地球
- 9. 谷歌地圖地理編碼OVER_QUERY_LIMIT
- 10. 谷歌地圖與地理編碼
- 11. 谷歌地圖地理編碼 - offsetWidth
- 12. 谷歌地圖地理編碼API
- 13. 地理編碼谷歌地圖和ASP
- 14. 谷歌地圖的地理編碼
- 15. 谷歌地圖地理編碼和ZERO_RESULTS
- 16. 谷歌地圖地理編碼差異
- 17. 谷歌地圖和地理編碼
- 18. Twitter的地理編碼谷歌地圖
- 19. 地理編碼使用谷歌地理編碼網路服務
- 20. 谷歌地理編碼器+谷歌地圖添加標記
- 21. 谷歌反向地理編碼api沒有谷歌地圖
- 22. 谷歌地理編碼從谷歌地圖
- 23. 谷歌地理編碼限制
- 24. openlayers和谷歌地理編碼器
- 25. 谷歌地理編碼和distancematrix差異
- 26. 谷歌地理編碼要求限制
- 27. 谷歌地理編碼API,免費?
- 28. 需要谷歌地理編碼英語
- 29. 谷歌地理編碼批量
- 30. json與谷歌地理編碼api
不過,這對我沒有幫助 – quak