我在响应式HTML页面上使用地图图片。挑战是在任何视口上放置保留在同一位置的标记(带链接)。
如何实现这一目标?
答案 0 :(得分:0)
使用jQuery指向一个marker.Here是一个代码,给你API密钥并给用户lat =“”和log =“”,placeId:“”。
点击此网站以创建API KEY = https://developers.google.com/maps/documentation/javascript/get-api-key
<div class="col-md-12 col-sm-6 col-xs-6">
<div id="map" style="height:260px; width: 100%;"></div>
</div>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=(Here is your API key) &libraries=places&callback=initMap">
</script>
<script>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 9.992656, lng: 76.290536},
zoom: 18
});
var infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.getDetails({
placeId: 'ChIJLWFBCEENCDsRuBtYV6pjFh4'
}, function(place, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location
});
google.maps.event.addListener(marker, 'mouseover', function() {
infowindow.setContent('<div><strong>' + place.name + '</strong><br>' +
place.formatted_address + '</div>');
infowindow.open(map, this);
});
}
});
}
</script>