[英]Google Maps Retina Marker with Label
I am handling Google Maps for Retina with this code:我正在使用以下代码处理 Retina 版 Google 地图:
var marker = new google.maps.Marker({
position: new google.maps.LatLng(lat, lon),
title: title,
map: map,
id: id,
icon: {
url: "http://maps.google.com/mapfiles/kml/paddle/orange-blank.png",
size: new google.maps.Size(64, 64),
scaledSize: new google.maps.Size(40, 40),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(0, 0)
},
label: level + ""
});
It works that the Icon itself is scaled that it is sharp on retina display.它的工作原理是图标本身被缩放到它在视网膜显示上很清晰。 But as you can see on this Image the Label is not in the center of the Marker anymore.
但是正如您在此图像上所看到的,标签不再位于标记的中心。 How to handle that?
怎么处理? I already tried with origin and anchor without success.
我已经尝试过 origin 和 anchor 没有成功。 (The red marker is google original marker, unfortunately google doesn't have a Method to change the color of the standard marker or is there sth available?)
(红色标记是谷歌原始标记,不幸的是谷歌没有改变标准标记颜色的方法,或者有什么可用的?)
var marker = new google.maps.Marker({
position: new google.maps.LatLng(lat, lon),
title: title,
map: map,
id: id,
icon: {
url: "http://maps.google.com/mapfiles/kml/paddle/orange-blank.png",
size: new google.maps.Size(64, 64),
scaledSize: new google.maps.Size(40, 40),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(20, 40),
labelOrigin: new google.maps.Point(20,12)
},
label: level + ""
});
code snippet:代码片段:
function initialize() { var map = new google.maps.Map( document.getElementById("map_canvas"), { center: new google.maps.LatLng(37.4419, -122.1419), zoom: 13, mapTypeId: google.maps.MapTypeId.ROADMAP }); var title = "title"; var id = "id"; var level = 2; var lat = map.getCenter().lat(); var lon = map.getCenter().lng(); var marker = new google.maps.Marker({ position: new google.maps.LatLng(lat, lon), title: title, map: map, id: id, icon: { url: "http://maps.google.com/mapfiles/kml/paddle/orange-blank.png", size: new google.maps.Size(64, 64), scaledSize: new google.maps.Size(40, 40), origin: new google.maps.Point(0, 0), anchor: new google.maps.Point(20, 40), labelOrigin: new google.maps.Point(20, 12) }, label: level + "", anchorPoint: new google.maps.Point(0, -40) }); var infowindow = new google.maps.InfoWindow(); infowindow.setContent(marker.getPosition().toUrlValue(6)); infowindow.open(map, marker); } google.maps.event.addDomListener(window, "load", initialize);
html, body, #map_canvas { height: 100%; width: 100%; margin: 0px; padding: 0px }
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script> <div id="map_canvas"></div>
Fixed with:固定:
icon: {
url: "http://maps.google.com/mapfiles/kml/paddle/red-blank.png",
size: new google.maps.Size(32, 42),
scaledSize: new google.maps.Size(32, 32),
origin: new google.maps.Point(0, -10),
anchor: new google.maps.Point(16, 42)
}
And for others using that images there are a lot of colors just try...对于使用该图像的其他人来说,有很多颜色只是尝试......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.