저는 Symfony2를 기반으로 한 프로젝트를 진행하고 있습니다. Google지도 생성에 IvoryGoogleMapBundle 번들을 사용하고 있습니다. 지도의 경우 현재 사용자 좌표를 중심으로해야합니다.
이를 위해 서버 측 솔루션 대신 Geolocation HTML5 API를 사용하고 싶습니다.
번들 문서에는이 경우에 대한 솔루션이 없습니다.
IvoryGoogleMap으로 생성 된 Google지도에이 기능을 추가하는 우아한 방법은 무엇입니까?
우리는 그것을 생성하기 위해 서비스를 사용합니다. 그러나지도의 기본 설정은 매우 간단합니다.
/** var \Ivory\GoogleMapBundle\Model\MapBuilder $map */
$map = $mapBuilder->build();
// any additional config goes here.
// make sure you set the Javascript Variable name like so:
$map->setJavascriptVariable('your_awesome_map');
{{ google_map_container(map) }}
{{ google_map_js(map) }}
javascript
파일을 설정하고 템플릿에 포함합니다. 이 파일에서 다음과 같이 할 수 있습니다.
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(updateMap, error);
}
function updateMap(position) {
// location determined
}
position
다음과 같이 현재 위치를 포함합니다.
position.coords.latitude, position.coords.longitude
예를 들어지도를 중앙에 배치합니다. 자바 스크립트 변수를 통해 서비스에서 생성 한지도에 액세스 할 수 있습니다 your_awesome_map
.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다