2012-05-22 68 views
0

我想從下面的代碼做兩件事情:谷歌地圖顯示問題

  1. 如果地理編碼不是全成不顯示在地圖(到目前爲止我只隱藏的錯誤消息。 )
  2. 如果成功,則只能在重新加載地址之前加載地址而不是原始地址。

你將不得不原諒所有的單引號,在PHP回聲下的javascript加載。

任何想法的歡迎,理想情況下,我想在JavaScript處理它,但不介意一點的PHP,如果需要,我期待在網站的幾個區域使用它。

echo ' 
<script type="text/javascript"> 
var geocoder; 
var map; 
function initialize() { 
    geocoder = new google.maps.Geocoder(); 
    var latlng = new google.maps.LatLng(51.500141,-0.125195);   
    var address = \''.$company.', '.$address_l1.', '.$address_l2.', '.$address_l3.', '.$town.', '.$county.', '.$post_code.', '.$country.'\';        
    var myOptions = { 
     zoom: 16, 
     scrollwheel: false, 
     navigationControl: false, 
     mapTypeControl: false, 
     scaleControl: false, 
     streetViewControl: false, 
     center: latlng, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    } 
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 
    geocoder.geocode({ \'address\': address}, function(results, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
      map.setCenter(results[0].geometry.location); 
      var marker = new google.maps.Marker({ 
       map: map, 
       position: results[0].geometry.location 
      }); 
     } else { 
      //alert("Geocode was not successful for the following reason: " + status); 
     } 
    }); 
} 
</script>   
<div id="map_canvas"></div> 
'; 
+0

您是否嘗試將map = new google.maps ..移至地理編碼成功功能 – gunnx

+0

謝謝@ gunnx肯定適用於問題2,圍繞問題1的任何想法?我對JavaScript很陌生,所以這有點超過我的頭! –

+0

什麼是問題1? – gunnx

回答

0

移動地圖創建到的地理編碼的成功的功能和使用的document.getElementById(「map_canvas提供」)。的style.display =「塊」或者沒有顯示/隱藏上失效地圖。