2010-07-13 56 views
0

我即将开始实施谷歌地图V3到一个网站,有一个以前的谷歌地图版本。谷歌API V3鼠标悬停并致电

  1. 这是一个很难改变升级?

  2. 而且我需要API密钥添加到呼叫

    例如:

    新的呼叫

    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">

    以前调用

    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=someKEY">

  3. 最后,我需要将鼠标悬停在地址的链接上,地址显示在地图上,这是一项复杂的任务吗?

+0

你是否有一个具体问题?另外,我会检查上面粘贴的HTML;它似乎并不合法。 (我注意到当我修复格式时,但我不想改变它,以防万一这是你问题的根源。 – pkaeding 2010-07-13 14:13:49

回答

2
  1. 的命名空间,类名和第3版API的架构从V2 API完全改变了。我不会致电升级,但这不是微不足道的。进一步阅读:Announcing Google Maps API v3

  2. 您不再需要v3 API的API密钥。只需包括您在问题中提到的脚本。

  3. 对悬停地址进行地理编码并不是非常困难。你可能想看看下面的例子,以帮助您入门:

例子:

<!DOCTYPE html> 
<html> 
<head> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
    <title>Google Maps Geocoding On Hover</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> 

    <ul> 
    <li><a href="#" onmouseover="gc(this);">Oxford Street, London, UK</a></li> 
    <li><a href="#" onmouseover="gc(this);">5th Ave, New York, USA</a></li> 
    <li><a href="#" onmouseover="gc(this);">Via Nazionale, Rome, Italy</a></li> 
    <li><a href="#" onmouseover="gc(this);">Rue de Rivoli, Paris, France</a></li> 
    </ul> 

    <script type="text/javascript"> 
    var address = 'London, UK'; 

    var map = new google.maps.Map(document.getElementById('map'), { 
     mapTypeId: google.maps.MapTypeId.ROADMAP, 
     center: new google.maps.LatLng(40.71, -74.00), 
     zoom: 13 
    }); 

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

    function gc(element) { 
     geocoder.geocode({ 
      'address': element.innerHTML 
     }, 
     function(results, status) { 
      if(status == google.maps.GeocoderStatus.OK) { 

      // Clear the previous marker 
      if (marker) marker.setMap(null); 

      // Set the new marker 
      marker = new google.maps.Marker({ 
       position: results[0].geometry.location, 
       map: map 
      }); 

      // Center the map on the geocoded result 
      map.setCenter(results[0].geometry.location); 
      } 
     }); 
    } 

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

截图:

Google Maps Geocoding OnMouseOver