2010-07-17 123 views
4

我有一個web應用程序。我想集成Google地圖,以顯示用戶在搜索位置鍵入的位置的地圖。任何幫助?如何將Google地圖集成到Web應用程序中?

+0

要顯示您公司的位置? – sathish 2010-07-17 08:30:23

+0

不完全。該位置是用戶願意通過地圖看到的東西。我不想透露更多細節,因爲它是保密的。 – 2010-07-17 08:34:36

回答

3

如果我正確理解你的問題,你希望你的用戶搜索一個位置,然後顯示它在地圖上。如果是這種情況,那麼可以使用Google Maps JavaScript API提供的Geocoding Services很容易地完成。請看下面的例子:

<!DOCTYPE html> 
<html> 
<head> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
    <title>Google Maps Geocoding Demo</title> 
    <script src="http://maps.google.com/maps/api/js?sensor=false" 
      type="text/javascript"></script> 
</head> 
<body> 
    <div id="map" style="width: 400px; height: 300px;"></div> 

    <script type="text/javascript"> 

    var address = 'London, UK'; 

    var map = new google.maps.Map(document.getElementById('map'), { 
     mapTypeId: google.maps.MapTypeId.TERRAIN, 
     zoom: 6 
    }); 

    var geocoder = new google.maps.Geocoder(); 

    geocoder.geocode({ 
     'address': address 
    }, 
    function(results, status) { 
     if(status == google.maps.GeocoderStatus.OK) { 
     new google.maps.Marker({ 
      position: results[0].geometry.location, 
      map: map 
     }); 
     map.setCenter(results[0].geometry.location); 
     } 
     else { 
     // Google couldn't geocode this request. Handle appropriately. 
     } 
    }); 

    </script> 
</body> 
</html> 

截圖:

Google Maps v3 Geocoding Demo

你可以簡單地替代address變量,在這個例子中設置爲'London, UK'由用戶搜索的位置的值。

0

第1步:打開你想嵌入的地圖。它可以是您在地圖標籤下創建的地圖,也可以是地址,本地商戶或駕車路線搜索。

第2步:單擊「鏈接到此頁面」後,從文本框中複製HTML代碼。您還可以在嵌入之前自定義地圖的大小並預覽它。

第3步:將HTML代碼粘貼到您的網站或您的博客編輯器中。

否則請參閱本網站 http://www.higheredblogcon.com/library/deweese/presentation.html

相關問題