2012-01-27 8 views
0

私はopen.phpにフィールドアドレスを持っています。ユーザーが何かを書き始めると、自動補完用のGoogleアドレスがあります。ユーザーが住所を選択すると、地図上にマーカーが配置され、緯度/経度フィールドに値が入力されます。 、フィールドに値を設定する

<input id="address" type="text" value="<?php echo $_GET['query']; ?>"/> 

をしかし、その後JSスクリプトは、マップを移入するために実行されません。

は今、私はその後open.phpがURLからアドレスを取得し、前のページでアドレス欄を埋め、ユーザーのデ可能性を追加しました緯度と経度。これをどうすれば解決できますか?

(私は、ユーザーの可能性を必要とするユーザーがopen.phpに直接入力することができますので、前のページのアドレスフィールドを埋める)

ありがとうございます!

JSからコード:

var geocoder; 
var map; 
var marker; 

function initialize(){ 
//MAP 
    var latlng = new google.maps.LatLng(49.599,6.134); 
    var options = { 
    zoom: 14, 
    center: latlng, 
    mapTypeId: google.maps.MapTypeId.HYBRID 
    }; 

    map = new google.maps.Map(document.getElementById("map_canvas"), options); 

    //GEOCODER 
    geocoder = new google.maps.Geocoder(); 

    marker = new google.maps.Marker({ 
    position: latlng, 
    map: map, 
    animation: google.maps.Animation.BOUNCE, 
    draggable: true 
    }); 

} 

$(document).ready(function() { 

    initialize(); 

    $(function() { 
    $("#address").autocomplete({ 
     //This bit uses the geocoder to fetch address values 
     source: function(request, response) { 
     // geocoder.geocode({'address': request.term }, function(results, status) { 
     geocoder.geocode({'address': request.term + ', lu' }, function(results, status) { 
      response($.map(results, function(item) { 
      return { 
       label: item.formatted_address, 
       value: item.formatted_address, 
       latitude: item.geometry.location.lat(), 
       longitude: item.geometry.location.lng() 
      } 
      })); 
     }) 
     }, 
     //This bit is executed upon selection of an address 
     select: function(event, ui) { 
     $("#latitude").val(ui.item.latitude); 
     $("#longitude").val(ui.item.longitude); 
     var location = new google.maps.LatLng(ui.item.latitude, ui.item.longitude); 
     marker.setPosition(location); 
     map.setCenter(location); 
     } 
    }); 
    }); 

    //Add listener to marker for reverse geocoding 
    google.maps.event.addListener(marker, 'drag', function() { 
    geocoder.geocode({'latLng': marker.getPosition()}, function(results, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
     if (results[0]) { 
      $('#address').val(results[0].formatted_address); 
      $('#latitude').val(marker.getPosition().lat()); 
      $('#longitude').val(marker.getPosition().lng()); 
     } 
     } 
    }); 
    }); 

}); 

enter code here 

答えて

0

$('#address').trigger('change'); 
のようなものを試してみてください
関連する問題