Tôi có một trang kéo vào trường học, nhà thờ và công viên của khu vực đã cho nhưng tôi muốn tạo kiểu cho 3 POI với 3 biểu tượng khác nhau. Tôi đã tìm kiếm trên Google và thậm chí tất cả tài liệu nhưng không thể tìm thấy câu trả lời.API Google Maps v3 Điểm ưa thích với các biểu tượng tùy chỉnh
var map;
var infowindow;
function initialize() {
// Center of Map
var centerLatlng = new google.maps.LatLng(29.745376, -95.380125);
// Marker Icons Declaration
var icon = new google.maps.MarkerImage("smLinks-twitter.png", null, null, new google.maps.Point(41,47));
// Map Options
var myOptions = {
zoom: 16,
center: centerLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
icons: icon
};
// Draw the map
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
// Marker Icons Implementation
markers = new google.maps.Marker({
position: centerLatlng,
map: map,
title: 'Center of Map',
icon: icon
});
// Services: Places
var request = {
location: centerLatlng,
radius: 800,
types: ["school", "church", "park"]
};
infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.search(request, callback);
} // function initialize()
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
createMarker(results[i]);
}
}
}
function createMarker(place) {
var placeLoc = place.geometry.location;
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location,
icon: icon
});
google.maps.event.addListener(marker, 'mouseover', function() {
infowindow.setContent(place.name + '<br/>' + place.vicinity + '<br/><img src="' + place.icon + '">');
infowindow.open(map, this);
});
}
MaryAnne, chỉ cần cố gắng dụ của bạn và nó hoạt động hoàn hảo. Tôi biết nó là một mảng tôi cần nhưng không chắc chắn làm thế nào các API muốn thiết lập mảng. –
Cảm ơn câu lệnh chuyển đổi bổ sung. –