在Angular-Google-Maps中添加标记

用户名

我目前在将点击标记添加到Google地图时遇到了一些麻烦。我正在使用http://angular-ui.github.io

这是我的代码:HTML:

<ui-gmap-google-map center='map.center' zoom='map.zoom' events="map.events">
  <ui-gmap-marker coords="map.marker.coords" idKey="map.marker.id"></ui-gmap-marker>
</ui-gmap-google-map>

还有我的JS:

$scope.map = {
    center: {
        latitude: alat.value, longitude: alon.value },
        zoom: 15,
        streetViewControl: false,
        events: {
            click: function (map, eventName, originalEventArgs) {
                var e = originalEventArgs[0];
                var lat = e.latLng.lat(),lon = e.latLng.lng();
                $scope.map.marker = {
                    id: 1,
                    coords: {
                        latitude: lat,
                        longitude: lon
                    }
                };
                $scope.$apply();
            }
        }
    };

我一直在使用Angular-Google-Maps API,但到目前为止,我对Google Maps API并不十分满意。到目前为止,我已经推断出click事件确实有效,但是我的标记尚未添加到地图中。帮助将不胜感激。

杰拉姆

我制造了小提琴这是HTML。

<div ng-app="main" ng-controller="mainCtrl">
    <ui-gmap-google-map center="map.center" zoom="map.zoom" draggable="true" events="map.events">
        <ui-gmap-marker ng-repeat="m in map.markers" coords="m.coords" icon="m.icon" idkey="m.id"></ui-gmap-marker>
    </ui-gmap-google-map>
</div>

控制器就是这样。

angular.module('main', ['uiGmapgoogle-maps'])
.controller('mainCtrl', function ($scope) {

    angular.extend($scope, {
        map: {
            center: {
                latitude: 42.3349940452867,
                longitude:-71.0353168884369
            },
            zoom: 11,
            markers: [],
            events: {
            click: function (map, eventName, originalEventArgs) {
                var e = originalEventArgs[0];
                var lat = e.latLng.lat(),lon = e.latLng.lng();
                var marker = {
                    id: Date.now(),
                    coords: {
                        latitude: lat,
                        longitude: lon
                    }
                };
                $scope.map.markers.push(marker);
                console.log($scope.map.markers);
                $scope.$apply();
            }
        }
        }
    });
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

无法使用angular-google-maps中的标记标签打开标记窗口

来自分类Dev

Google Maps异步添加标记

来自分类Dev

Google Maps异步添加标记

来自分类Dev

Android Google Maps,如何在标记中添加链接

来自分类Dev

无法使用angular-google-maps中的markers标签打开标记窗口

来自分类Dev

Android Google Maps异步任务添加标记

来自分类Dev

Google Maps使用jquery从ajax添加标记

来自分类Dev

在div点击添加Google Maps标记

来自分类Dev

Google Maps:添加硬编码标记以循环

来自分类Dev

标记的angular2-google-maps点击事件

来自分类Dev

使用Angular Maps在Google地图中放置标记

来自分类Dev

Google Maps Angular Js

来自分类Dev

如何使用Ionic&Angular在Google Maps API v3中实现居中标记

来自分类Dev

Typescript或Angular 2中的Google Maps

来自分类Dev

如何在Google Maps API中添加多个叠加标记

来自分类Dev

在Google Maps API v2 Android中添加多个标记

来自分类Dev

使用URL方案将标记添加到iOS中的Google Maps

来自分类Dev

使用React.js在Google Maps Javascript API中添加标记的问题

来自分类Dev

如何在Google Maps API v3中将类添加到标记

来自分类Dev

为Google Maps API中的现有标记添加信息窗口

来自分类Dev

在Google Maps Android中动态更新标记

来自分类Dev

更改Google Maps方向中的单个标记

来自分类Dev

数组列表中Google Maps上的标记

来自分类Dev

AngularJS中Google Maps的路线标记

来自分类Dev

使用AngularJS在Google Maps中实现标记

来自分类Dev

在Google Maps标记中创建标签

来自分类Dev

数组列表中Google Maps上的标记

来自分类Dev

在Google Maps标记中创建标签

来自分类Dev

在google-maps-react的Google Maps的标记下添加标记标签

Related 相关文章

热门标签

归档