栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

带有多个标记的AngularJS Google Map

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

带有多个标记的AngularJS Google Map

// 1. Google Map // var cities = [    {        city : 'Location 1',        desc : 'Test',        lat : 52.238983,        long : -0.888509     },    {        city : 'Location 2',        desc : 'Test',        lat : 52.238168,        long : -52.238168    },    {        city : 'Location 3',        desc : 'Test',        lat : 52.242452,        long : -0.889882     },    {        city : 'Location 4',        desc : 'Test',        lat : 52.247234,        long : -0.893567     },    {        city : 'Location 5',        desc : 'Test',        lat : 52.241874,        long : -0.883568     }];FCCAppCtrl.controller('MapController', function($scope, $ionicLoading) {    // Map Settings //    $scope.initialise = function() {        var myLatlng = new google.maps.LatLng(37.3000, -120.4833);        var mapOptions = { center: myLatlng, zoom: 16, mapTypeId: google.maps.MapTypeId.ROADMAP        };        var map = new google.maps.Map(document.getElementById("map"), mapOptions);      // Geo Location /        navigator.geolocation.getCurrentPosition(function(pos) { map.setCenter(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude)); var myLocation = new google.maps.Marker({     position: new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude),     map: map,     animation: google.maps.Animation.DROP,     title: "My Location" });        });        $scope.map = map;        // Additional Markers //        $scope.markers = [];        var infoWindow = new google.maps.InfoWindow();        var createMarker = function (info){ var marker = new google.maps.Marker({     position: new google.maps.LatLng(info.lat, info.long),     map: $scope.map,     animation: google.maps.Animation.DROP,     title: info.city }); marker.content = '<div >' + info.desc + '</div>'; google.maps.event.addListener(marker, 'click', function(){     infoWindow.setContent('<h2>' + marker.title + '</h2>' + marker.content);     infoWindow.open($scope.map, marker); }); $scope.markers.push(marker);        }          for (i = 0; i < cities.length; i++){ createMarker(cities[i]);        }    };    google.maps.event.addDomListener(document.getElementById("map"), 'load', $scope.initialise());});


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/668778.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号