Я перерыл весь Интернет и попробовал несколько решений, но не могу найти, как совместить свое собственное местоположение и в то же время показать некоторые маркеры на карте.
Я получил этот код для отображения нескольких маркеров, и он отлично работает, но как мне также назвать свое собственное местоположение с помощью карт Google? Я знаю, что есть документация о том, как добавить свое собственное местоположение, но не о том, как объединить эти два параметра.
Изменить в отношении дубликатов:
В stackoverflow нет подобных вопросов, и поэтому нет дубликатов, поскольку нет вопросов относительно объединения нескольких маркеров и отображения собственного маркера местоположения.
Вот код, который я получил прямо сейчас:
<script>
function initialize() {
var map;
var bounds = new google.maps.LatLngBounds();
var mapOptions = {
mapTypeId: 'roadmap'
};
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
map.setTilt(45);
var markers = [
['some locations, city', 52.35475,19.532567],
['some locations, city', 52.35475,19.532567],
['some locations, city', 52.35475,19.532567],
['some locations, city', 52.35475,19.532567],
['some locations, city', 52.35475,19.532567],
['some locations, city', 52.35475,19.532567],
['some locations, city', 52.35475,19.532567]
];
var infoWindowContent = [
['<div class="info_content">' +
'<h3>London Eye</h3>' +
'<p>The London Eye is a giant Ferris wheel situated on the banks of the River Thames. The entire structure is 135 metres (443 ft) tall and the wheel has a diameter of 120 metres (394 ft).</p>' + '</div>'],
['<div class="info_content">' +
'<h3>Palace of Westminster</h3>' +
'<p>The Palace of Westminster is the meeting place of the House of Commons and the House of Lords, the two houses of the Parliament of the United Kingdom. Commonly known as the Houses of Parliament after its tenants.</p>' +
'</div>']
];
var infoWindow = new google.maps.InfoWindow(), marker, i;
// Here we get our own location
var showPosition = function (position) {
var userLatLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
var marker = new google.maps.Marker({
position: userLatLng,
title: 'Your Location',
map: map
});
}
// Show all the markers and show my own location. Show my own location don't work.
for( i = 0; i < markers.length; i++ ) {
var position = new google.maps.LatLng(markers[i][1], markers[i][2], showPosition);
bounds.extend(position);
marker = new google.maps.Marker({
position: position,
map: map,
title: markers[i][0]
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infoWindow.setContent(infoWindowContent[i][0]);
infoWindow.open(map, marker);
}
})(marker, i));
map.fitBounds(bounds);
}
var boundsListener = google.maps.event.addListener((map), 'bounds_changed', function(event) {
this.setZoom(11);
google.maps.event.removeListener(boundsListener);
});
}
</script>