在Google地图中绘制匿名圈子 [英] Drawing anonymous circles in Google Maps

查看:126
本文介绍了在Google地图中绘制匿名圈子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图绘制一个具有多个Circle叠加层的Google地图,但我不想揭示半径的正确中心。



例如, myLatlng 是我的纬度/经度半径的中心,我想绘制一个不在其周围的圆,但是一个包含的圆。



这是我现在如何绘制我的圈子:

  var myLatlng = new google.maps.LatLng(33.33333,22.22222); 
var circle = new google.maps.Circle({
map:map,
radius:3218,
strokeColor:#FFAA00,
fillColor:# 00AAFF,
fillOpacity:0.3,
center:myLatlng,
zIndex:99999,

});

33.33333,22.22222 是一个'秘密'我不想透露的位置,但我希望在该圈内有这一点。



这可能吗?



谢谢!

解决方案

在您的示例代码中。这个圆可以移动到任何地方,这样33.3和22.2仍然可以被包括在内。

一种方法是简单地添加一个随机偏移量。
$ b

  //在-5和5之间生成随机数(仅举例)
var latOffset = Math.floor(Math.random()* 11 ) - 5;
var longOffset = Math.floor(Math.random()* 11) - 5;
var myLatlng = new google.maps.LatLng(33.33333 + latOffset,22.22222 + longOffset);

棘手的问题是确保随机偏移量不会将圆圈移出的界限。维基百科上将经度和纬度表示为线性单位部分应该有所帮助。

I'm trying to draw a google maps that has multiple Circle overlays, however I do not want to reveal the correct center of the radius.

So for example, myLatlng is my lat/lon center of the radius, I want to draw a circle not around it, but a circle that will include that point.

This is how I currently draw my circle:

        var myLatlng = new google.maps.LatLng(33.33333,22.22222);
        var circle = new google.maps.Circle({
              map: map,
              radius: 3218,
              strokeColor: "#FFAA00",
              fillColor: "#00AAFF",
              fillOpacity: 0.3,
              center: myLatlng,
              zIndex: 99999,

        });

33.33333,22.22222 is a 'secret' location that I do not want to reveal, however I would like to have that point within the circle.

Is that possible?

Thanks!

解决方案

In your example code. The circle could move anywhere such that 33.3 and 22.2 could still be included.

One way to do this would be to simply add a random offset.

    // Generate random between -5 and 5 (just an example)
    var latOffset = Math.floor(Math.random()*11) - 5;
    var longOffset = Math.floor(Math.random()*11) - 5;
    var myLatlng = new google.maps.LatLng(33.33333 + latOffset,22.22222 + longOffset);

The tricky bit you've got is to ensure that the random offset doesn't move the circle out of bounds. The section Expressing latitude and longitude as linear units on Wikipedia should help.

这篇关于在Google地图中绘制匿名圈子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆