2012-04-12 3 views

Antwort

0

Nun habe ich das in PHP .. Bitte den Code finden .. Sie einen Anruf AJAX und das wird Breiten- und Längen zurückkehrt .. wie

$address = $this->input->post('address'); 
     $output = array(); 

     $address = str_replace(" ", "+", $address); 
     $region = "IND"; 
     $json = file_get_contents("http://maps.google.com/maps/api/geocode/json?address=$address&sensor=false&region=$region"); 

     $json = json_decode($json); 

     if (!empty($json->{'results'}[0]->{'geometry'}->{'location'}->{'lat'})) { 
      $output['latitude'] = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lat'}; 

      $output['longitude'] = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lng'}; 


return $output; 
     } 

Dann Stelle gesetzt mit der zurückgegebenen Breite & Länge mit Google Karte API

//var latlng = new google.maps.LatLng(-104.017031, 15.373535); 
     var latlng = new google.maps.LatLng(latitude,longitude); 
     var map = new google.maps.Map(document.getElementById('map'), { 
     center: latlng, 
     zoom: 13, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }); 


    var marker = new google.maps.Marker({ 
     position: latlng, 
     map: map, 
     title: 'Set lat/lon values for this property', 
     raiseOnDrag: true, 
     draggable: true 
    }); 
    google.maps.event.addListener(marker, 'dragend', function(a) { 
     console.log(a); 

     $('#latitude').val(a.latLng.lat().toFixed(4)); 
     $('#longitude').val(a.latLng.lng().toFixed(4)); 

     // var div = document.createElement('div'); 
     // div.innerHTML = a.latLng.lat().toFixed(4) + ', ' + a.latLng.lng().toFixed(4); 
     // document.getElementsByTagName('body')[0].appendChild(div); 
    }); 

Geben Sie bitte google map.js Datei auf Ihrer Seite

this helps

Verwandte Themen