Я использую API Карт Google вместе с API Street View и API Geocoder, чтобы отобразить карту с несколькими маркерами, заголовок / описание для каждого, их адрес и относительное изображение вида улицы.
Вот код:
var geocoder;
var markers = [{
"title": 'Title',
"lat": '40.0000',
"lng": '10.0000',
"description": 'Description',
"type": 'Red'
}, {
"title": 'Title 2',
"lat": '41.0000',
"lng": '11.0000',
"description": 'Description2',
"type": 'Green'
}];
window.onload = function () {
geocoder = new google.maps.Geocoder();
var mapOptions = {
center: new google.maps.LatLng(markers[0].lat, markers[0].lng),
scrollwheel: false,
minZoom: 11,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var infoWindow = new google.maps.InfoWindow();
var latlngbounds = new google.maps.LatLngBounds();
var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
var i = 0;
var interval = setInterval(function () {
var data = markers[i]
var myLatlng = new google.maps.LatLng(data.lat, data.lng);
var icon = "";
switch (data.type) {
case "Red":
icon = "https://maps.google.com/mapfiles/ms/icons/red.png";
break;
case "Blue":
icon = "https://maps.google.com/mapfiles/ms/icons/blue.png";
break;
case "Green":
icon = "https://maps.google.com/mapfiles/ms/icons/green.png";
break;
}
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: data.title,
icon: new google.maps.MarkerImage(icon)
});
(function (marker, data) {
google.maps.event.addListener(marker, "click", function (e) {
geocoder.geocode({
'latLng': marker.getPosition()
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
infoWindow.setContent("<h3>" + marker.title + "</h3>" + "<small><em><strong>Marker address:</strong> "+results[0].formatted_address+ "</em></small><br><br>" + data.description + "<img src='https://maps.googleapis.com/maps/api/streetview?key=xxxxxxxxxsize=400x400&location="+results[0].geometry.location+"&fov=90&heading=235&pitch=10' />");
infoWindow.open(map, marker);
} else {
infoWindow.setContent('<h3>' + marker.title + '</h3>' + data.description);
infoWindow.open(map, marker);
}
});
});
})(marker, data);
latlngbounds.extend(marker.position);
i++;
if (i == markers.length) {
clearInterval(interval);
var bounds = new google.maps.LatLngBounds();
map.setCenter(latlngbounds.getCenter());
map.fitBounds(latlngbounds);
}
}, 0);
}
Все работает хорошо, за исключением URL-адреса img Просмотр улиц, который отображается с круглыми скобками до и после местоположения (и, следовательно, возвращает 404). Пример: https://maps.googleapis.com/maps/api/streetview?key=xxxxxx&size=400x400&location=(61.880901,%2022.467498)&fov=90&heading=235&pitch=10
Как вывести +results[0].geometry.location+
в виде строки через запятую, чтобы избавиться от скобок?