2016-04-08 138 views
0

试图像this谷歌静态地图 - 画一个圆

enter image description here

创建一个圆圈静态地图在path参数我不明白如何获取enc部分。这似乎是一些编码路径,包括圆/长和圆的大小。

https://maps.googleapis.com/maps/api/staticmap? 
center=51.44208,5.47308& 
zoom=14& 
size=693x648& 
path=color:blue|fillcolor:0x00d2c196|weight:1| 
enc%3Aad_yHofn%60%40JyFh%40sF%60AcFxAmElBqD~BoCnCiBtC_AzCUzCTvC~%40lChB~BnCnBpDxAlE%60AbFf%40rFLxFMxFg%40rFaAbFyAlEoBpD_CnCmChBwC~%40%7BCT%7BCUuC_AoCiB_CoCmBqDyAmEaAcFi%40sFKyF%3F%3F 

Link to Google's documentation

**编辑:发现这些:

Drawing a circle Google Static Maps

Encoded Polyline Algorithm Format

+1

相关的问题:[GMAP绘图工具来图像JPEG(静态地图URL)](http://stackoverflow.com/questions/31277220/gmap-drawing-tools-to-image- jpeg-static-map-url) – geocodezip

+2

你想要哪个圈子?你想要它的半径是什么?您需要使用这些参数创建折线,然后对其进行编码以创建编码多边形,以便在静态地图上显示。 – geocodezip

+0

Thx结果在下面! – Bxx

回答

1

这就是我想出了:

function funcStaticMapWithCircle($lat, $lng) { 

    //$lat & $lng are center of circle 

    $mapCentLat = $lat + 0.002; 
    $mapCentLng = $lng - 0.011; 
    $mapW =   600; 
    $mapH =   600; 
    $zoom =   14; 

    $circRadius =  0.75;   //Radius in km 
    $circRadiusThick = 1; 
    $circFill =   '00BFFF'; 
    $circFillOpacity = '60'; 
    $circBorder =  'red'; 

    $encString = GMapCircle($lat,$lng,$circRadius); //Encoded polyline string 


    $src = 'https://maps.googleapis.com/maps/api/staticmap?'; 
    $src .= 'center=' .$mapCentLat. ',' .$mapCentLng. '&'; 
    $src .= 'zoom=' .$zoom. '&'; 
    $src .= 'size=' .$mapW. 'x' .$mapH.'&'; 
    $src .= 'maptype=roadmap&'; 
    $src .= 'style=feature:water|element:geometry.fill|color:0x9bd3ff&'; 
    $src .= 'path='; 
    $src .= 'color:0x' .$circBorder. '00|'; 
    $src .= 'fillcolor:0x' .$circFill.$circFillOpacity. '|'; 
    $src .= 'weight:' .$circRadiusThick. '|'; 
    $src .= 'enc:' .$encString; 


    return $src; 
} 

GMapCircle功能是从:Drawing a circle Google Static Maps