[英]How can I use Circles instead of markers with my Google Maps
基本上,您只需要使用SVG圆形路径定义一个对象,并将其分配给标记的icon
属性。 这是我执行类似操作的部分代码。 请注意,您将需要使用path
定义和/或scale
属性来获得所需的结果,但这演示了整体配方:
// Somewhere in your code you define an object you'll use as an icon.
// You only need to instantiate this once.
var circleIcon = {
path: 'M 0, 0 m -10, 0 a 10, 10 0 1, 0 20, 0 a 10, 10 0 1, 0 -20, 0',
fillColor: '#00FFFF',
fillOpacity: 0.0,
scale: 1,
strokeColor: '#00FFFF',
strokeWeight: 2,
strokeOpacity: 0.8
};
// Then elsewhere in your code you can create markers like this.
// Many markers can reference the same icon object.
var latLng = new google.maps.LatLng(33.9958, -80.8896);
var circleMarker = new google.maps.Marker({
icon: circleIcon
position: latLng,
map: map
});
// Optionally, you can use methods like these set marker properties.
//circleMarker.setPosition(latLng );
//circleMarker.setVisible(true);
//circleMarker.setMap(map);
另一方面,关于保留“一点点隐私”,听起来您的圆心仍然代表着用户的真实位置。 因此,您可能要考虑将一些微妙的随机偏移量引入到地理编码器中的LatLng
坐标中。 根据对十进制度数的快速回顾,纬度和经度值的波动范围为0.001 +/- 0.001至0.009,应该使您有大约100至1000米的晃动,这可能足以满足您的目的。 如果我这样做的话,我可能会看一些样本点,然后将它们的真实位置与它们的“随机偏移”位置进行比较,然后再使用它,主要是为了对它进行真实性检查。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.