Javascript AngularJS和AngularGoogle地图:通过fomr添加标记并找到我

Javascript AngularJS和AngularGoogle地图:通过fomr添加标记并找到我,javascript,google-maps,angularjs,Javascript,Google Maps,Angularjs,我试图从中复制这个例子,因为它实现了我想要的90% 但到目前为止,我还没有取得多大成功,它可以找到我的位置,因为我可以控制台记录它,但它没有在地图上放置标记。。“addMarker”函数似乎可以工作,但控制台日志是returnig[Object][Object],而不是输入的值 我想做的是通过lat+lng表单添加标记,并且在按下“查找我”按钮时添加标记 到目前为止,我掌握的代码是: HTML: <html ng-app="typeApp" class="no-js"> ...

我试图从中复制这个例子,因为它实现了我想要的90%

但到目前为止,我还没有取得多大成功,它可以找到我的位置,因为我可以控制台记录它,但它没有在地图上放置标记。。“addMarker”函数似乎可以工作,但控制台日志是returnig[Object][Object],而不是输入的值

我想做的是通过lat+lng表单添加标记,并且在按下“查找我”按钮时添加标记

到目前为止,我掌握的代码是:

HTML:

<html ng-app="typeApp" class="no-js">

...

<body ng-controller="MainCtrl">

...

      <a class="button" ng-click="findMe()" href="">Find me</a>

      <table class="table">
          <tr>
            <td><input type="number" class="" ng-model="markerLat" name="markerLat" required=""></td>
            <td><input type="number" class="" ng-model="markerLng" name="markerLng" required=""></td>
            <td><button class="button" ng-click="addMarker()">Add</button></td>
          </tr>
      </table>
console.log('Found You:'+position.coords.latitude+'| |'+position.coords.longitude')输出我的坐标,但地图不更新。
console.log('Maker add:'+$scope.markers)输出[Object][Object]


任何帮助都将不胜感激。谢谢。

如果您正在动态加载位置(通过浏览器),则应在可用时添加ng If=“position”,If将翻转ng If语句并开始摘要


如果在标记元素上添加ng,则此代码正常。您只缺少一个变量

您必须添加$scope.map.center,而不是$scope.center,如下所示:

$scope.map.center={纬度:位置.坐标.纬度,经度:位置.坐标.经度}

scope.markers也一样。尝试scope.map.markers。还没有测试,但它应该可以工作

'use strict';

var module = angular.module('typeApp', ['ngCookies',
    'ngResource',
    'ngSanitize',
    'ngRoute',
    'google-maps',
    'pageslide-directive'
]);

module.config(function ($routeProvider) {
$routeProvider
  .when('/', {
    templateUrl: 'views/main.html',
    controller: 'MainCtrl'
  })
  .when('/login', {
    templateUrl: 'views/login.html',
    controller: 'loginCtrl'
  })
  .otherwise({
    redirectTo: '/404.html'
  });
});

module.controller('MainCtrl', function ($scope) {

    //Default location
    $scope.center = {
        latitude: 45,
        longitude: -73
    };

    $scope.geolocationAvailable = navigator.geolocation ? true : false;

    $scope.latitude = null;
    $scope.longitude = null;

    $scope.zoom = 6;

    $scope.styles = [
        {
          stylers: [
            { hue: "#00ffe6" },
            { saturation: -20 }
          ]
        },{
          featureType: "road",
          elementType: "geometry",
          stylers: [
            { lightness: 100 },
            { visibility: "simplified" }
          ]
        },{
          featureType: "road",
          elementType: "labels",
          stylers: [
            { visibility: "off" }
          ]
        }
    ];

    $scope.markers = [];

    $scope.markerLat = null;
    $scope.markerLng = null;

    $scope.addMarker = function () {

        $scope.markers.push({
            latitude: parseFloat($scope.markerLat),
            longitude: parseFloat($scope.markerLng)
        });

        $scope.markerLat = null;
        $scope.markerLng = null;
        console.log('Maker add: ' + $scope.markers);
    };  

    $scope.findMe = function () {

        if ($scope.geolocationAvailable) {

            navigator.geolocation.getCurrentPosition(function (position) {

                $scope.center = {
                    latitude: position.coords.latitude,
                    longitude: position.coords.longitude
                };

                $scope.$apply();
                console.log('Found You: ' + position.coords.latitude + ' || ' + position.coords.longitude);
            }, function () {

            });
        }   
    };

});