-1

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

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

4

1 回答 1

-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>      
于 2013-10-04T11:24:32.800 回答