2013-10-04 111 views
-1

我的桌面應用程序中有一個樹形視圖和一個Web瀏覽器,其中的樹形視圖包含座標值列表或者說功能的質心現在什麼我只想在用戶點擊任何樹視圖節點時在我的網頁瀏覽器google map api上顯示特定點。使用谷歌地圖API在谷歌地圖上顯示功能

先決條件: - 1.當用戶點擊樹形視圖節點時,我們獲得了地圖座標以顯示在谷歌地圖上,我已經使用谷歌地圖API在我的網絡瀏覽器中設置了它。

回答

-1
**you need to replace your key with googleapikey and set your key and you need to use below script with set your values to and from address** 

    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true&amp;key=yourgoogleapikey" type="text/javascript"> 


    <script type="text/javascript"> 
     //<![CDATA[ 
     var toAddress = "650 Franklin Street, Suite 306, Schenectady, NY, 12305, USA"; 
     var directions; //Google directions object 
     window.onload = getDir; 
     var fromStreet = ''; 
     var fromZip = "12345"; 
     var dirpanel; 
     var divMap; 

     function getDir() { 
      if (!directions) { 
       divMap = document.getElementById("divMap"); 
       dirMap = new GMap2(divMap); 
       dirMap.addControl(new GLargeMapControl()); 
       dirMap.addControl(new GScaleControl()); 

       dirpanel = document.getElementById("divRoute"); 
       directions = new GDirections(dirMap, dirpanel); 
       GEvent.addListener(directions, "error", handleErrors); 
      } 

      //Clear Directions, if any 
      dirpanel.innerHTML = ""; 

      var fromAddress = ''; 
      //At least starting zip/city & state is needed to get the directions 

      if (fromZip.length > 0) { 
       if (fromStreet.length > 0) 
        fromAddress = fromStreet + ", "; 
       fromAddress += fromZip; 
       directions.load("from: " + fromAddress + " to: " + toAddress); 
       divMap.style.visibility = ""; 
      } 

     } 

     function handleErrors() { 
      divMap.style.visibility = "hidden"; 
      if (directions.getStatus().code == G_GEO_UNKNOWN_ADDRESS) { 
       alert("We are unable to show directions for the starting address you entered.\nThis may be because the from address is relatively new, or it may be incorrect."); 
      } 
      else { 
       alert("We apologize!\n\nWe are currently unable to display directions for this location"); 
      } 
     } 

     //]]> 
    </script>