居中谷歌地图在LatLon上的SymbolPath [英] Centering google maps SymbolPath on LatLon
本文介绍了居中谷歌地图在LatLon上的SymbolPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试过使用锚点,但无济于事。
以下是我的示例代码:
var marker = new google.maps.Marker({
位置:new google.maps.LatLng(50.124462,-5.539994),
图标:{
路径:google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
比例:8,
strokeWeight: 2,
fillColor:'#009933',
fillOpacity:1,
rotation:210,
anchor:new google.maps.Point(0,0)
},
});
marker.setMap(map);
解决方案
2.6)
最简单的实验方法是取消旋转,然后使用锚点来查看它的位置。
var marker = new google.maps.Marker({
position:new google.maps.LatLng(50.124462,-5.539994),
icon:{
path:google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
比例:8,
strokeWeight:2,
fillColor:'#009933',
fillOpacity:1,
rotation:210,
anchor:new google.maps.Point(0,2.6)
},
});
工作代码片段:
var map; function init(){var startLatLng = new google.maps.LatLng(50.124462,-5.539994); map = new google.maps.Map(document.getElementById('map-canvas'),{center:startLatLng,zoom:12}); var marker = new google.maps.Marker({position:new google.maps.LatLng(50.124462,-5.539994),map:map}); var marker = new google.maps.Marker({position:new google.maps.LatLng(50.124462,-5.539994),icon:{path:google.maps.SymbolPath.FORWARD_CLOSED_ARROW,scale:8,strokeWeight:2,fillColor:' #009933',fillOpacity:1,rotation:210,anchor:new google.maps.Point(0,2.6)},}); marker.setMap(map);} google.maps.event.addDomListener(window,'load',init);
html,body,#map-canvas {height:100%;宽度:100%; margin:0px; < script src =https:// //maps.googleapis.com/maps/api/js\"></script><div id =map-canvasstyle =border:2px solid#3872ac;>< / div>
Is there a way to get the google.maps.SymbolPath.FORWARD_CLOSED_ARROW to put the center of the icon at the LatLng position. It seems to be putting the point of the arrow there.
I have tried to experiment with the anchor but to no avail.
Here is my example code:
var marker=new google.maps.Marker({
position: new google.maps.LatLng(50.124462, -5.539994),
icon: {
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
scale: 8,
strokeWeight: 2,
fillColor: '#009933',
fillOpacity: 1,
rotation: 210,
anchor: new google.maps.Point(0, 0)
},
});
marker.setMap(map);
解决方案
For that symbol, use an anchor of (0,2.6)
fiddle demonstrating that at various rotations
Simplest way to find experimentally is remove the rotation, then play with the anchor to see where it goes.
var marker = new google.maps.Marker({
position: new google.maps.LatLng(50.124462, -5.539994),
icon: {
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
scale: 8,
strokeWeight: 2,
fillColor: '#009933',
fillOpacity: 1,
rotation: 210,
anchor: new google.maps.Point(0,2.6)
},
});
working code snippet:
var map;
function init() {
var startLatLng = new google.maps.LatLng(50.124462, -5.539994);
map = new google.maps.Map(document.getElementById('map-canvas'), {
center: startLatLng,
zoom: 12
});
var marker = new google.maps.Marker({
position: new google.maps.LatLng(50.124462, -5.539994),
map: map
});
var marker = new google.maps.Marker({
position: new google.maps.LatLng(50.124462, -5.539994),
icon: {
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
scale: 8,
strokeWeight: 2,
fillColor: '#009933',
fillOpacity: 1,
rotation: 210,
anchor: new google.maps.Point(0, 2.6)
},
});
marker.setMap(map);
}
google.maps.event.addDomListener(window, 'load', init);
html,
body,
#map-canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map-canvas" style="border: 2px solid #3872ac;"></div>
这篇关于居中谷歌地图在LatLon上的SymbolPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文