2010-11-26 4 views
0

Google지도에로드 한 마커 위치 (다른 정보와 함께)를 저장 한 MySQL 데이터베이스가 있습니다. 나는 예를 들어 다음 -MySQL 데이터베이스에서 마커를 어떻게 동적으로로드 할 수 있습니까?

http://code.google.com/apis/maps/articles/phpsqlajax.html

을하고 나를 위해 잘 일했다.

이제 사용자가 특정 마커의 ID를 선택하고지도를로드 할 버튼을 클릭 할 수 있다고 가정합니다. 지도에서 특정 마커를 동적으로로드하는 방법을 모릅니다.

어떤 종류의 도움을 주시면 감사하겠습니다.

답변

3

예 : here을 설정했습니다.
Ajax 요청 아래와 같이 나는 좌표

$.getJSON("getjson.php?address="+address, 
    function(data){ 
    lat=data.results[0].geometry.location.lat; 
    lng=data.results[0].geometry.location.lng; 
    point= new google.maps.LatLng(lat,lng); 
    map.setCenter(point); 
    zoom = 14; 
    marker = createMarker(point,"<h3>Marker"+(markersArray.length+1)+" "+point+"</h3>",zoom); 
}); 

를 얻기 위해 사용자와 구글 API V3를 사용하여 마커를 작성하여 입력 한 주소의 좌표를 수신하기 위해 구글 지오 코딩 API를 사용하고 PHP 코드는 마커

를 만들기 좌표

<?php 

$address = $_GET['address']; 
$address=str_replace(" ","+",$address); 
if ($address) { 
$json = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address='.$address. 
'&sensor=true'); 
echo $json; 
} 

?> 

를 반환

function createMarker(latlng, html,zoom) { var contentString = html; var marker = new google.maps.Marker({ position: latlng, map: map, zIndex: Math.round(latlng.lat()*-100000)<<5 }); google.maps.event.addListener(marker, 'click', function() { infowindow.setContent(contentString); infowindow.open(map,marker); }); marker.MyZoom = zoom; return marker; } 
1

먼저 링크를 보면 v2를 사용한다는 사실을 알았습니다. v2가 사용되지 않으므로 처음부터 v3을 사용하십시오.

귀하의 질문에 따라 절차를 말씀 드릴 수 있습니다. 그러면 절차가 완료 될 수 있습니다.


1. 사용자의 상호 작용
사용자 UI 및 가격의 선택 즉, 범위 (0 ~ 100)과 상호 작용한다.

2. Ajax 요청
클라이언트는 jquery getJson() 또는 다른 방법으로 JSON을 얻기 위해 서버에 아약스 요청을 보냅니다.

3. 서버에 응답
하는 PHP 페이지는 Ajax 호출에 응답하고 위치 마커, converts it in json의 결과 집합을 받고 MySQL의에서 쿼리를하고 다시 보낼 수 있습니다.

4.
클라이언트로 Parse the json 및 마커를 만들 구문 분석 응답.

0

안녕 나는이 일에 큰 도움 http://www.svennerberg.com/2012/03/adding-multiple-markers-to-google-maps-from-json/

링크를 주어진 JSON 개체를 만들고 자바 스크립트에 전달 발견했다.

함수 createMarker JSON() {

for (var i = 0, length = json.length; i < length; i++) { 
    var data = json[i], 
    latLng = new google.maps.LatLng(data.lat, data.lng);   
    // Creating a marker and putting it on the map 
    var marker = new google.maps.Marker({ 
    position: latLng, 
    map: map, 
    title: data.title 
    }); 
} 

}

관련 문제