我想在谷歌地图上放置针点。但问题是我有很多地方要点,而我这样做的方式有点困难。有一个简单的方法吗?
我这样做的方式
.controller('MapCtrl', function($scope, $ionicLoading, $compile, $state) {
function initialize() {
//variables for adding the coordinates of the locations
var Chunnakam = new google.maps.LatLng(9.741527 ,80.033931);
var Nelliady = new google.maps.LatLng( 9.828288,80.220362);
var Karaditoku_Kilinochchi = new google.maps.LatLng(9.380289,80.377);
//alot more of these come after this
并且我会像这样放置点
var marker = new google.maps.Marker({
position: Chunnakam,
map: map,
title: 'Chunnakam'
});
var marker2 = new google.maps.Marker({
position: Nelliady,
map: map,
title: 'Nelliady'
});
//
var marker3 = new google.maps.Marker({
position: Karaditoku_Kilinochchi,
map: map,
title: 'Karaditoku Kilinochchi'
});
有一种简单的方法吗?谢谢。
答案 0 :(得分:0)
你可以创建一个对象数组并迭代它:
var towns = [ { marker: null, name: 'Chunnakam', lat: 9.741527, lng: 80.033931 },
{ marker: null, name: 'Nelliady', lat: 9.828288, lng: 80.220362 },
// add new towns here
];
angular.forEach(towns, function(town) {
town.marker = new google.maps.Marker({
position: new google.maps.LatLng(town.lat, town.lng),
map: map,
title: town.name
});
}