2010-09-22 711 views

回答

5

你可以做的是使用encoded polyline algorithm产生足够的点来获得一个大致的圆形路径。确实存在编码问题:您需要获取圆的中心和半径,将其转化为一系列经纬度,然后使用该算法进行编码。

作为替代方案,您可能能够使用一个透明的gif图片作为标记,并把在你的地图。

+2

注意,标记有大小限制。 100px乘100px对我不起作用,但75px乘75px。 – kingjeffrey 2011-04-15 18:56:21

+0

的问题是,这取决于你最终可能会需要一分不少,使其真正看起来像一个圆圈,因此,你可能无法达到URL字符圆的长度(有1024个字符的限制目前) – renatoargh 2017-05-11 23:16:00

+0

2048个字符,对不起 – renatoargh 2017-05-12 13:47:35

1

这是可能的,但你必须绘制形状有很多面的,看起来像一个圆圈。

这是我的例子:

<img src="http://maps.google.com/maps/api/staticmap?size=600x500&path=fillcolor:0x0000FF|weight:3|color:0xFF0000|enc:ue{cI|rrH`@[email protected]@[email protected][email protected][email protected]@[email protected]@[email protected]@`[email protected]@dWy`@nX{]vY{ZxZuWx[kTr\_Qh]oMz]}If^iFl^uBn^?n^tBd^hFz]|Ih]nMr\~Px[jTxZtWvYzZnXz]dWx`@[email protected]`T`[email protected]@[email protected]@[email protected]@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected][email protected]`[email protected]@[email protected]@[email protected]@[email protected]@eWx`@oX|]wYzZyZtWy[jTs\~Pi]lM{]|Ie^jFo^rBo^?m^sBg^kF{]}Ii]mMs\_Qy[kTyZuWwY{ZoX}]eWy`@[email protected]@[email protected]@[email protected]{[email protected]@[email protected][email protected]@[email protected]@[email protected]&sensor=true" border="0"/> 

Or try this link to view it

为了产生这个我以前freemaptools.com

+0

任何方式来使这种动态?如果我有许多不同的坐标使用? – 2015-03-23 13:51:16

+0

@JonasB这是可能的。寻找折线生成器。如果这有什么用处,我已经为此做了一个角度指示? – sidonaldson 2015-03-27 20:28:56

+0

这是值得注意的,网站使用PHP折线编码器(来自客户端的源代码:'xmlHttp.open( “POST”, “AJAX/CSV-折线-encoder.php”,TRUE);')。 – 2016-02-25 15:22:45

5

您可以通过绘图详细PolyLine表示绕圈,因为谷歌静态地图不支持自己画一个圆圈。

Here is a request example包含2圈半径0.5和5公里。请记住,您需要一个算法才能生成正确的编码多段线。我使用这个implementation,因为我是用PHP编写的,但是你可以根据你想要的语言自己找到或开发类似的东西。

这里是我用来生成请求的PHP代码:

<?php 
/* set some options */ 
$mapLat = filter_input(INPUT_POST, 'lat1'); // latitude for map's and circle's center 
$mapLng = filter_input(INPUT_POST, 'lon1'); // longitude for map's and circle's center 
$mapRadius1 = 0.5; // the radius of the first circle (in Kilometres) 
$mapRadius2 = 5; // the radius of the second circle (in Kilometres) 
$mapFill_first = '330000'; // fill colour of the first circle 
$mapFill_second = 'FF99FF'; // fill colour of the second circle 
$map1Border1 = '91A93A'; // border colour of the first circle 
$map1Border2 = '0000CC'; // border colour of the second circle 
$mapWidth = 450; // map image width (max 640px) 
$mapHeight = 450; // map image height (max 640px) 
$zoom = 11; 
$scale = 2; 
/** create our encoded polyline string for the first circle*/ 
$EncString1 = GMapCircle($mapLat, $mapLng, $mapRadius1); 
/** create our encoded polyline string for the second circle*/ 
$EncString2 = GMapCircle($mapLat, $mapLng, $mapRadius2); 
/** put together the static map URL */ 
$MapAPI = 'http://maps.google.com.au/maps/api/staticmap?'; 
$MapURL = $MapAPI . 'center=' . $mapLat . ',' . $mapLng . '&zoom=' . $zoom . '&size=' . 
    $mapWidth . 'x' . $mapHeight . '&scale=' . $scale . '&markers=color:red%7Clabel:S%7C'.$mapLat.','.$mapLng . 
    '&maptype=roadmap&path=fillcolor:0x' . $mapFill_first . 
    '33%7Ccolor:0x' . $map1Border1 . '00%7Cenc:' . $EncString1 . '&path=fillcolor:0x' . 
    $mapFill_second . '33%7Ccolor:0x' . $map1Border2 . '00%7Cenc:' . $EncString2; 

/* output an image tag with our map as the source */ 
//echo '<img src="' . $MapURL . '" />'; 
echo json_encode($MapURL); 

function GMapCircle($Lat, $Lng, $Rad, $Detail = 8) 
{ 
    $R = 6371; 
    $pi = pi(); 
    $Lat = ($Lat * $pi)/180; 
    $Lng = ($Lng * $pi)/180; 
    $d = $Rad/$R; 
    $points = array(); 
    for ($i = 0; $i <= 360; $i += $Detail) 
    { 
     $brng = $i * $pi/180; 
     $pLat = asin(sin($Lat) * cos($d) + cos($Lat) * sin($d) * cos($brng)); 
     $pLng = (($Lng + atan2(sin($brng) * sin($d) * cos($Lat), cos($d) - sin($Lat) * sin($pLat))) * 180)/$pi; 
     $pLat = ($pLat * 180)/$pi; 
     $points[] = array($pLat, $pLng); 
    } 

    require_once('PolylineEncoder.php'); 
    $PolyEnc = new PolylineEncoder($points); 
    $EncString = $PolyEnc->dpEncode(); 

    return $EncString['Points']; 
} 

由于jomacinc的教程,享受:)

3

您可以通过使用computeOffset方法很容易接近的圆这可以让你沿着圆周找到坐标。

在这个例子中我使用的8度的增量,所以这会给45双坐标。对于圆圈大小,我使用的是在静态地图中很好地显示的圆圈。如果您使用大圆圈,则只需将增量更改为更小的值,例如j = j + 6。

将变量pathText添加到静态地图所需的其余网页地址。

var pathText = '&path='; 
var circumLatLng; 

for (var j = 0; j < 361; j = j + 8) { 

circumLatLng = google.maps.geometry.spherical.computeOffset(circle.getCenter(), circle.getRadius(), j); 

pathText += circumLatLng.lat().toFixed(6) + ',' + circumLatLng.lng().toFixed(6) + '|'; 
}