【问题标题】:Unable to add marker on map inside webview无法在 webview 内的地图上添加标记
【发布时间】:2016-02-15 11:09:59
【问题描述】:

我是 Webview 的初学者,试图通过 $interval 在 webview 上动态绘制标记。我正在使用 google map api v3 和 angular google map library ng-map.js:

<html style="overflow: auto !important;" ng-app="myApp">
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=weather,visualization,panoramio"></script>
<script src="JS/angular.min.js"></script>

<script src="JS/ng-map.min.js"></script>
<script>
 var app = angular.module('myApp', ['ngMap']);
 app.controller("PolylineComplexCtrl", function (NgMap, $interval, $scope) {

    $interval(function (position) {
        navigator.geolocation.getCurrentPosition(function (position) {

            new google.maps.Marker({
                position : {
                    lat : position.coords.latitude,
                    lng : position.coords.longitude
                },
                map : $scope.map,
                draggable : false,
                animation : google.maps.Animation.BOUNCE
            });
        });
    }, 1000);

    var vm = this;
    vm.path = [[41.879535, -87.624333]];
    vm.addMarkerAndPath = function (event) {
        vm.path.push([event.latLng.lat(), event.latLng.lng()]);
    };
 });
</script>
</head>

<body ng-controller="PolylineComplexCtrl as vm">
  <ng-map zoom="7" center="21.1500,79.0900" on-click="vm.addMarkerAndPath()">
    <shape name="polyline" id="foo"
      path="{{vm.path}}"
      stroke-color="#FF0000"
      stroke-opacity="1.0"
      stroke-weight="3">
    </shape>
  </ng-map>
</body>
</html>

在浏览器上一切正常,但是当我在 webview 上运行它时它不起作用。我错过了什么?

【问题讨论】:

  • 什么不能在移动设备上运行?您是否使用带有某些框架(Ionic,...)的cordova?

标签: javascript android angularjs google-maps


【解决方案1】:

也许您在手机上收听地图点击事件时遇到问题,所以我建议您查看这些帖子:

ng-map on-click doesn't work on mobile

how can i bind touch events for a marker in google maps?

【讨论】:

    猜你喜欢
    • 2016-05-10
    • 2015-08-18
    • 2012-12-23
    • 1970-01-01
    • 2014-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-16
    相关资源
    最近更新 更多