2010-09-22 712 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) + '|'; 
}