如何向标记添加 over (hoover) 事件以显示地址

发布于 2024-11-23 19:46:35 字数 79 浏览 5 评论 0原文

在谷歌地图中,​​当我添加标记时,我希望它成为一个气泡,其中包含谷歌为该位置提供的地址。 我必须使用哪些选项来发送标记对象(或者它是标记对象?)

In google Maps, When I add a marker, I want it to be a bubble with the address Google came up with to that location.
What options do I have to send the marker object (or is it the marker object?)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

裂开嘴轻声笑有多痛 2024-11-30 19:46:36

我可以使用以下 google-maps-api-v3 javascript 嵌入代码绘制/冒泡给定的地址/邮政编码(不超过 8 个)。

 <!DOCTYPE html>
 <html>
 <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>Google Maps JavaScript API v3 Example: Directions Waypoints</title>
    <link href="http://code.google.com/apis/maps/documentation/javascript/examples/standard.css" rel="stylesheet" type="text/css" />
    <script src="https://maps-api-ssl.google.com/maps/api/js?v=3&sensor=false"  type="text/javascript"></script>
    <script type="text/javascript">
       function initialize() {

            var directionDisplay;
            var directionsService = new google.maps.DirectionsService();

            var map;
            directionsDisplay = new google.maps.DirectionsRenderer();

            var chicago = new google.maps.LatLng(41.850033, -87.6500523);
            var myOptions = {
            zoom: 6,
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            center: chicago }

            var waypts = [];
            var PtsArray = [];

            //Give input as postcode/place name as a single string seperated by pipeline character as follows. 
            var PointsString = "LE126UW" + "|" + "NG104AH" + "|" + "B112RJ" + "|" + "London";            


            PtsArray = PointsString.split("|");

            var length = PtsArray.length;
            if (length > 2) {
            for (i = 1; i < (length - 1); i++) {
               waypts.push({
                   location: String(PtsArray[i]),
                   stopover: true
                });
             }
           }

         var request = {
           origin: String(PtsArray[0]),
           destination: String(PtsArray[length - 1]),
           waypoints: waypts,
           optimizeWaypoints: false,//set this to true to get optimized path else it will plot as the given input.
           travelMode: google.maps.DirectionsTravelMode.DRIVING//set your travel mode here (walking,driving..)
          };


           directionsService.route(request, function (response, status) {

              if (status == google.maps.DirectionsStatus.OK) {
                  map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
                  directionsDisplay.setMap(map);
                  directionsDisplay.setDirections(response);
                  var route = response.routes[0];
                  var total = 0;
                  var numberLegs = route.legs.length;
               }
               else {
                   alert("Could not load data.." + status);
               }
         });
      }       

 </script>

希望这也能帮助你...

I could plot/bubble the given addresses/postcodes(not more than eight) using the following google-maps-api-v3 javascript embed code.

 <!DOCTYPE html>
 <html>
 <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>Google Maps JavaScript API v3 Example: Directions Waypoints</title>
    <link href="http://code.google.com/apis/maps/documentation/javascript/examples/standard.css" rel="stylesheet" type="text/css" />
    <script src="https://maps-api-ssl.google.com/maps/api/js?v=3&sensor=false"  type="text/javascript"></script>
    <script type="text/javascript">
       function initialize() {

            var directionDisplay;
            var directionsService = new google.maps.DirectionsService();

            var map;
            directionsDisplay = new google.maps.DirectionsRenderer();

            var chicago = new google.maps.LatLng(41.850033, -87.6500523);
            var myOptions = {
            zoom: 6,
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            center: chicago }

            var waypts = [];
            var PtsArray = [];

            //Give input as postcode/place name as a single string seperated by pipeline character as follows. 
            var PointsString = "LE126UW" + "|" + "NG104AH" + "|" + "B112RJ" + "|" + "London";            


            PtsArray = PointsString.split("|");

            var length = PtsArray.length;
            if (length > 2) {
            for (i = 1; i < (length - 1); i++) {
               waypts.push({
                   location: String(PtsArray[i]),
                   stopover: true
                });
             }
           }

         var request = {
           origin: String(PtsArray[0]),
           destination: String(PtsArray[length - 1]),
           waypoints: waypts,
           optimizeWaypoints: false,//set this to true to get optimized path else it will plot as the given input.
           travelMode: google.maps.DirectionsTravelMode.DRIVING//set your travel mode here (walking,driving..)
          };


           directionsService.route(request, function (response, status) {

              if (status == google.maps.DirectionsStatus.OK) {
                  map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
                  directionsDisplay.setMap(map);
                  directionsDisplay.setDirections(response);
                  var route = response.routes[0];
                  var total = 0;
                  var numberLegs = route.legs.length;
               }
               else {
                   alert("Could not load data.." + status);
               }
         });
      }       

 </script>

Hope this helps you too...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文