使用谷歌地图API在谷歌地图上显示功能(桌面应用程序包含一个网络浏览器)

本文关键字:谷歌地图 包含一 应用程序 浏览器 桌面 网络 功能 API 显示 | 更新日期: 2023-09-27 18:33:58

我的桌面应用程序中有一个树视图和一个 Web 浏览器,其中树视图包含坐标值列表或说特征质心,现在我只想在我的网络浏览器谷歌地图 API 上显示特定点当用户单击任何树视图节点时。

前提:-1.当用户单击树视图节点时,我们得到了地图坐标以显示在谷歌地图上,我已经使用谷歌地图API在我的网络浏览器中设置了该坐标。

使用谷歌地图API在谷歌地图上显示功能(桌面应用程序包含一个网络浏览器)

**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>