2012-08-30 3 views
0

나는 구글지도 API와 PHP

http://jsfiddle.net/DanielMontenegro/7pdU4/3/

지금, 나는 사람들이 지오 코딩 서비스를 통해 어떤 특별한 이벤트를보고 할 수 있도록 사이트에이지도를 넣어 원하는 supose이 코드를 가지고있다. 나는 그 테이블의 이벤트의 주소/좌표를 어떻게 얻을 수 있는지를 물어보고, 사용자 보고서를 하나의 데이터베이스로 모으고 싶다.

답변

1

아래 코드를 참조하십시오.

나는 당신이 당신의 데이터베이스를 연결하고 당신의 필요 조건에 따라 배열을 만들 수 있습니다 PHP를 정적 배열을 사용하고 있습니다. 아래 배열을보십시오.

<?php $item = array('jaipur, rajasthan,india', 'udaipur, rajasthan,india'); ?> 

아래 내 코드보세요.

<html> 
    <head> 
     <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=AIzaSyDwFjOazEAe1MI7nHV6vUwkWytOp8LH2Zk" type="text/javascript"></script> 
    </head> 
    <body onload="initialize();"> 
    <?php $item = array('jaipur, rajasthan,india', 'udaipur, rajasthan,india'); ?> 
    <script> 
    var map = null; 
    var geocoder = null; 

    function initialize() { 
      if (GBrowserIsCompatible()) { 


        map = new GMap2(document.getElementById("map_canvas")); 
        var addresses = ["<?php echo implode ('","', $item); ?>"] 


        var geocoder = new GClientGeocoder(); 
        //var addresses = ["A II Z, Ibn Battuta Mall, Sheikh Zayed Road, 5th Interchange, Jebel Ali Village, Dubai","A. Testoni,Dubai Festival City Mall, Ground Floor, Dubai", "Abdulla Hussain Khunji, The Dubai Mall,Downtown, Abu Dhabi"]; 
        var curIndex = 0; 

        function showAddress() { 
         var _cur = addresses[curIndex]; 
         geocoder.getLatLng(
         _cur, 
         function(point) { 
          if (!point) { 
          //alert(_cur + " not found"); 
          //map.setCenter(new GLatLng(0, 0), 6); 
          //map.setUIToDefault(); 
          } else { 
          //console.log(_cur+":"+point); 
          //alert(_cur); 
            var cafeIcon = new GIcon(G_DEFAULT_ICON); 

            // Set up our GMarkerOptions object 
            markerOptions = { icon:cafeIcon }; 

            map.setCenter(point, 6); 
            var marker = new GMarker(point, markerOptions); 
            map.addOverlay(marker); 

            var sales = new Array(); 
            sales = _cur.split("|"); 


            //Add click event on push pin to open info window on click of the icon 
            GEvent.addListener(marker, "click", function() { 
              marker.openInfoWindowHtml("<p class='para1bold' style=\"font-weight: bold;\">Address <br /><span class='para1' style='font-weight:normal;'>" + sales[1] + "</span></p>"); 
            }); 
            //Provides map,satellite,hybrid and terrain views in the map along with zoom control 


            map.setUIToDefault(); 
          } 
          //do next after done 

          curIndex++; 

          if(curIndex<addresses.length) 
          showAddress(); 
         } 
        ); 
        } 
        showAddress(); 
     } 
    } 
    </script> 
    <div id="map_canvas" style="width:100%; height:750px;"></div> 
    </body> 
</html> 
1

당신은 (지도에서 사용자가 클릭을 수신 할 바람직 리스너) 어떤 종류의 액션 청취자를 설정해야합니다. 그런 다음 위도/경도로 지오 코드를 지정하고 테이블에받은 것을 저장하십시오.

  1. 사용자가지도상의 한 점을 클릭합니다.
  2. 클릭 이벤트는 사용자가 클릭 한 시간을 나타냅니다.
  3. 위도/경도는 Ajax를 사용하여 텍스트 주소에 대해 지오 코딩됩니다.
  4. 위도/문자 및 텍스트 주소는 모두 데이터베이스 테이블에 나란히 저장됩니다. 이 일이처럼 보이는 "Articles" section of the documentation

    에 PHP/MySQL과 Google Maps API v3을 인터페이스에 대한 goood 많은 정보가있다