gpt4 book ai didi

javascript - Angular js : Unable to add marker in google map

转载 作者:行者123 更新时间:2023-11-30 11:55:32 25 4
gpt4 key购买 nike

我正在尝试在谷歌地图中添加标记,但不幸的是,它没有被添加。

map 上只有一个标记。

这是我的 HTML:

<div ng-app="myApp" ng-controller="gMap">
<ui-gmap-google-map
center='map.center'
zoom='map.zoom' aria-label="Google map">

<ui-gmap-marker ng-repeat="marker in markers"
coords="marker.coords" options="marker.options" events="marker.events" idkey="marker.id">
<ui-gmap-window>
<div>{{marker.window.title}}</div>
</ui-gmap-window>
</ui-gmap-marker>

</ui-gmap-google-map>
</div>

我的 Angular 代码如下所示:

var myApp = angular.module('myApp', ['uiGmapgoogle-maps']);

myApp.controller("gMap",function($scope){
$scope.map = {
center: { latitude: 39.8282, longitude: -98.5795 },
zoom: 4
};

$scope.markers.id = "1";
$scope.markers.coords.latitude = "40.7903";
$scope.markers.coords.longitude = "-73.9597";
$scope.markers.window.title = "Manhattan New York, NY";

});

CODEPEN

最佳答案

稍微改了一下代码,得到了结果。

var myApp = angular.module('myApp', ['uiGmapgoogle-maps']);

myApp.controller("gMap",function($scope){
$scope.map = {
center: { latitude: 39.8282, longitude: -98.5795 },
zoom: 4
};

$scope.marker = {
coords: { latitude: 39.8282, longitude: -98.5795 },
id: 4 ,
window: { title: "Manhattan New York, NY" }
};


});

HTML 变成了:

<div ng-app="myApp" ng-controller="gMap">
<ui-gmap-google-map
center='map.center'
zoom='map.zoom' aria-label="Google map">

<ui-gmap-marker
coords="marker.coords" options="marker.options" events="marker.events" idkey="marker.id">
<ui-gmap-window>
<div>{{marker.window.title}}</div>
</ui-gmap-window>
</ui-gmap-marker>

</ui-gmap-google-map>
</div>

CODEPEN

关于javascript - Angular js : Unable to add marker in google map,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38094204/

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