주소

2015-01-13 2 views
-1

나는주소

나는 또한 긴 위도 것은 그릴로이 주소를 변경하는 기능 지오 코더가 (테이블라는 이름의 임무에, 필드 주소는) 내 데이터베이스에 사람들의 일부 주소가 내지도의 마커. (EDIT)

내가 먹고 싶어 :

내가하는 방법을 이해하지 않는이 단지 물건을 내 데이터베이스에서 내 주소를 가지고

다음

내 코드 내지도에 그것을 사용하는 것입니다 내 데이터베이스의 주소를 내 지오 코더 함수의 '주소'필드에 입력하십시오. 하지만 그렇게 할 수 있습니까? 그렇다면 어떻게?

도움을 주셔서 감사합니다. (내가 분명 해요 희망 ^^ ')

편집 :

내의 .js

<script type="text/javascript"> 
    // When the window has finished loading create our google map below 

    var map; 
    var geocoder; 

    function initialize() { 
     geocoder = new google.maps.Geocoder(); 
     var mapOptions = { 
      zoom: 14 
     }; 
     map = new google.maps.Map(document.getElementById('map-geo'), mapOptions); 

     if(navigator.geolocation) { 
      var circle = new google.maps.Circle({ 
        center: new google.maps.LatLng(52.376018, 4.901962), 
        radius: 500, 
        map: map 
       }); 

      navigator.geolocation.getCurrentPosition(function(position) { 
       var pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); 
       accuracy = parseFloat(position.coords.accuracy); 
       map.setZoom(14); 
       circle.setCenter(pos); 
       circle.setRadius(accuracy); 
       map.fitBounds(circle.getBounds()); 
       var infowindow = new google.maps.InfoWindow({ 
        map: map, 
        position: pos, 
        content: 'Voici votre géolocalisation' 
       }); 

      //map.setCenter(pos); 
      }, function() { 
      circle.setMap(null); 
      handleNoGeolocation(true); 
     }); 
     } else { 
      // Browser doesn't support Geolocation 
      handleNoGeolocation(false); 
     } 
     $.ajax({ //create an ajax request to a page that prints the address. 
      url: "addMarkers.php", //url for the address page      
      success: function(result){ 
       var adresse = result; //create a variable and give it the value of the response data 
       codeAddress(adresse); //decode the address using codeAddress into Lat and Lon 
      } 
     }); 
     codeAddress(<?php echo $adresse; ?>); 
     //codeAddress(); 
    } 

    function codeAddress(adresse) { 
     geocoder.geocode({ 'address': "61 rue de la libération, 44230, saint sebastien sur loire"}, function(results, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
      var marker = new google.maps.Marker({ 
       map: map, 
       position: results[0].geometry.location 
      }); 
     } else { 
      alert('Geocode was not successful for the following reason: ' + status); 
     } 
     }); 
    } 

    function handleNoGeolocation(errorFlag) { 
     if (errorFlag) { 
     var content = 'Error: The Geolocation service failed.'; 
     } else { 
     var content = 'Error: Your browser doesn\'t support geolocation.'; 
     } 
    } 

    google.maps.event.addDomListener(window, 'load', initialize); 
</script> 

그리고 내 .PHP

<?php 
require_once("../admin/php/checklogin.php"); 
$host_name = "my_host"; 
$database = "my_db"; 
$bdduser_name = "my_name"; 
$bddpassword = "my_bddpass"; 

mysql_connect($host_name, $bdduser_name, $bddpassword) or die ("connection impossible."); 
mysql_select_db($database) or die ("connection bdd impossible."); 
//tu fais la connexion à la base puis: 

$sql="SELECT `id`, `nom`, `adresse`, `esc`, `cp`, `ville` 
FROM `missions` WHERE 1"; //remplaces par tes noms 

ini_set('mysql.trace_mode', true); 
mysql_set_charset('utf8'); 

$result = mysql_query($sql); 
?> 
+0

귀하의 정보를 위해서 * 주소 *는 영문으로 읽어야합니다. – MrUpsidown

+0

그래, 나는 모든 설명에 단 하나의 d를 넣었지만, 코드에 2 d가있다. –

답변

1

먼저 당신이 AJAX 요청을 사용할 수 있습니다 (것 jQuerythis으로 사용하는 것이 좋습니다)를 서버의 PHP 파일에 보내 주소 정보를 검색하십시오.

$.ajax({ //create an ajax request to a page that prints the address. 
    url: "getAddress.php", //url for the address page      
    success: function(response){      
     var address = response; //create a variable and give it the value of the response data 
     codeAddress(address); //decode the address using codeAddress into Lat and Lon 
    } 
}); 

제 생각에는 덜하지만 두 번째 방법은 PHP에서 javascript로 주소 변수를 직접 반영하는 것입니다.

codeAddress(<?php echo $address; ?>); 

올바른 방향으로 안내해주기를 바랍니다. PHP와 Javascript에 대해 잘 알고 있다면 목표를 달성 할 수 있어야합니다.

+0

예를 들어서 고마워, 내가 글을 올리면 대답 해 주겠다. ;-) –

+1

내가 편집 했어. 대답. 당신의 프로젝트에 행운을 빈다. 즐거운 프로그래밍을 기억해라 :) –

+2

확실히 옵션 1로 가라! – MrUpsidown