如何在google位置的函数内使用指令

时间:2017-03-06 10:42:29

标签: angularjs google-maps

我试图在我的angularjs项目中使用谷歌地图指令继承人指令:

.directive("myMaps", function(){
return{
    restrict:'E', //Element Type
    template:'<div></div>', //Defining myApp div
    replace:true, //Allowing replacing

    link: function($scope, element, attributes){

        $scope.title = attributes.title;
        $scope.type = attributes.type;
        alert('fdfd');
        alert($scope.title +'ddddddd'+$scope.type);


        //Initializing Coordinates
        var myLatLng = new google.maps.LatLng($scope.title,$scope.type); 
        var mapOptions = {
            center: myLatLng, //Center of our map based on LatLong Coordinates
            zoom: 5, //How much we want to initialize our zoom in the map
            //Map type, you can check them in APIs documentation
            mapTypeId: google.maps.MapTypeId.ROADMAP 
            };

        //Attaching our features & options to the map
        var map = new google.maps.Map(document.getElementById(attributes.id),
                      mapOptions);
        //Putting a marker on the center
        var marker = new google.maps.Marker({
            position: myLatLng,
            map: map,
            title:"My town"
        });
        marker.setMap(map); //Setting the marker up
    }   
};
})

它运作良好,但我如何在一个函数内调用它来获取新的经度和高度?

0 个答案:

没有答案