gpt4 book ai didi

javascript - 在 map 上添加标记: AngularJS

转载 作者:行者123 更新时间:2023-12-03 10:46:47 25 4
gpt4 key购买 nike

我很难应对 AngularJS 及其设置 map 和标记的方式。

现在我有以下代码:

<map data-ng-model="mymapdetail" zoom="11" 
center="{{item.coordinates}}" style="heigth:375px">
<div data-ng-model="mymarker"></div>
</map>

这正确地显示了居中的 map 。然后我尝试以这种方式添加标记。

$scope.mymarker = new google.maps.Marker({
map: $scope.mymapdetail,
position: new google.maps.LatLng(item.coordinates),
title: woa.title
});

此代码不会产生任何结果。哪里错了?

最佳答案

这是working solution单击时出现标记并 this one标记已经可见 - 使用您的代码(几乎 - 我没有使用 map 指令),但您应该能够通过很少的更改使其适应您的代码。它在您的情况下不起作用的主要原因可能是使用 new google.maps.LatLng(item.coordinates)

代码如下:

//Angular App Module and Controller
angular.module('mapsApp', [])
.controller('MapCtrl', function ($scope) {
var item = {
coordinates: [40.6423926, -97.3981926]
};

var woa = {
city: 'This is my marker. There are many like it but this one is mine.'
};


//set up map
var mapOptions = {
zoom: 4,
center: new google.maps.LatLng(40.0000, -98.0000),
mapTypeId: google.maps.MapTypeId.TERRAIN
};

$scope.mymapdetail = new google.maps.Map(document.getElementById('map'), mapOptions);

//add marker
$scope.mymarker = new google.maps.Marker({
map: $scope.mymapdetail,
animation: google.maps.Animation.DROP,
position: new google.maps.LatLng(item.coordinates[0], item.coordinates[1]),
title: woa.city
});

});

请告诉我它是否适合您。

关于javascript - 在 map 上添加标记: AngularJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28551056/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com