简体   繁体   English

角度Google Maps自定义标记

[英]Angular Google Maps Custom Marker

I'm having a hard time getting a custom marker icon to work with my google maps set up. 我很难让自定义标记图标可以与我的Google地图设置一起使用。 I just need one marker for the latitude and longitude that I pass in with my factory. 我只需要一个标记,就可以确定我在工厂中传递的经度和纬度。 I don't need multiple markers. 我不需要多个标记。

Inside my controller: 在我的控制器内:

var mapOptions = {
    panControl    : true,
    zoomControl   : true,
    scaleControl  : true,
    mapTypeControl: true,
    mapTypeId     : google.maps.MapTypeId.ROADMAP
};
$scope.map = ($scope,{
    center: {
        latitude: $scope.lat,
        longitude: $scope.long
    },
    zoom: 13,
    options: mapOptions,
    icon: '{url:"https://vacationcandy.com/assets/images/lollipin.png"}',
});
$scope.beachMarker = new google.maps.Marker({
    position: $scope.map.center,
    map: $scope.map,
    icon: '{url:"https://vacationcandy.com/assets/images/lollipin.png"}'
});
var updateCenter = function() {
    $scope.map.center.latitude= $scope.lat;
    $scope.map.center.longitude= $scope.long;
}
$scope.$watch('lat', function() {
    updateCenter();
});

Here is my HTML: 这是我的HTML:

<ui-gmap-google-map center='map.center' zoom='map.zoom' id='map-canvas' icon='"beachMarker.icon"'></ui-gmap-google-map>

I have tried a bunch of different things, even using the google marker directive inside ui-gmap-google-map but I can't seem to get it work. 我尝试了很多不同的方法,甚至在ui-gmap-google-map中使用google marker指令,但似乎无法正常工作。 What am I doing wrong? 我究竟做错了什么?

You don't add the marker at all do you? 您根本不添加标记吗? Try something along the lines (not tested): 尝试一些方法(未经测试):

<ui-gmap-google-map center="map.center" zoom="map.zoom" id="map-canvas">
  <ui-gmap-marker coords="map.center" icon="map.icon" idKey="1">
  </ui-gmap-marker>
</ui-gmap-google-map>

Check out docs before trying to hack your way into making it work with random examples on the web. 在尝试破解文档使其与网络上的随机示例配合使用之前,请先查看文档 Marker documentation is very clear. 标记文档非常清楚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM