2010-07-17 115 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

相关问题