2
GeoJSON 파일에서 정적 Google지도를 생성하기위한 URL을 얻을 수 있습니까?GeoJSON에서 Google Static 맵을 생성하는 방법은 무엇입니까?
감사합니다, 제레미
GeoJSON 파일에서 정적 Google지도를 생성하기위한 URL을 얻을 수 있습니까?GeoJSON에서 Google Static 맵을 생성하는 방법은 무엇입니까?
감사합니다, 제레미
좋아,이 나는 Static Google Map
에 사용자 정의를 MapBox.geojson
파일을 변환하는 방법입니다 : 이것은 내가 .geojson
로 변환 된 MapBox
지도입니다
지도 사용 : https://a.tiles.mapbox.com/v3/jeitnier.icm51ajc/markers.geojson. 파란색으로 채우기가 &이고 LineString
인 빨간색 획이있는 Polygon
경계가 있습니다.
당신은 사용자의 특정 요구에 맞게 일을 조정해야하지만이 요점이다
$url = 'https://a.tiles.mapbox.com/v3/jeitnier.icm51ajc/markers.geojson';
$response = \Utility::curl($url); // This is just a standard cURL function that returns the contents of the JSON
$geojson = json_decode($response);
$paths = '';
$markers = '';
foreach ($geojson->features AS $feature)
{
$properties = array();
if ('LineString' == $feature->geometry->type OR 'Polygon' == $feature->geometry->type)
{
$properties['stroke'] = substr($feature->properties->stroke, 1, 7);
$properties['stroke_width'] = $feature->properties->{'stroke-width'} - 1;
}
if ('LineString' == $feature->geometry->type)
{
$paths .= '&path=color:0x' . $properties['stroke'] . '99|weight:' . $properties['stroke_width'];
foreach ($feature->geometry->coordinates AS $set)
{
// put them in reverse order (lat/long) and convert to string
$paths .= '|' . $set[1] . ',' . $set[0];
}
}
elseif ('Polygon' == $feature->geometry->type)
{
$properties['fill'] = substr($feature->properties->fill, 1, 7);
$properties['fill_opacity'] = $feature->properties->{'fill-opacity'} * 100;
$paths .= '&path=color:0x' . $properties['stroke'] . '|weight:' . $properties['stroke_width'] . '|fillcolor:0x' . $properties['fill'] . $properties['fill_opacity'];
foreach ($feature->geometry->coordinates AS $coordinate)
{
// iterate over individual coordinate set
foreach ($coordinate AS $set)
{
// put them in reverse order (lat/long) and convert to string
$paths .= '|' . $set[1] . ',' . $set[0];
}
}
}
elseif ('Point' == $feature->geometry->type)
{
$markers .= '&markers=scale:' . $this->scale;
$markers .= '|' . $feature->geometry->coordinates[1] . ',' . $feature->geometry->coordinates[0];
}
}
// set map parameters
$params = array(
'key' => Config::get('custom.google_map_api_key'),
'zoom' => 16,
'size' => '300x300',
'format' => 'png32',
'scale' => '2',
'sensor' => 'false',
);
$url = 'http://maps.googleapis.com/maps/api/staticmap?' . http_build_query($params) . $markers . $paths;
코드입니다. 필자가 작성한 코드는 마커를 지원하며 다각형은 & 개의 줄만 필요했습니다.
혹시 이것을 알아 냈습니까? 나는 똑같은 일을 할려고한다. –
아니, 지금까지 아무것도 ... – jchatard
나는이 일을하고있다. 내 코드를 약간 게시 할 것입니다. –