Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何获取圆的纬度和经度';创建该标记的边界是什么?_Javascript_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 如何获取圆的纬度和经度';创建该标记的边界是什么?

Javascript 如何获取圆的纬度和经度';创建该标记的边界是什么?,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,这是我的地图工厂 我画了一个带有多个标记的圆,但我想在圆的末端(/outline of circle)添加一个标记,以便动态更改半径。但我无法设置该标记的位置(纬度和经度) sidemenu.factory('Map', function( $rootScope , $compile,$location,mapPlacesGeocoder,centerCoordinatesForMap,getMapObject){ // alert($location.path()); var

这是我的地图工厂

我画了一个带有多个标记的圆,但我想在圆的末端(/outline of circle)添加一个标记,以便动态更改半径。但我无法设置该标记的位置(纬度和经度)

sidemenu.factory('Map', function( $rootScope , $compile,$location,mapPlacesGeocoder,centerCoordinatesForMap,getMapObject){
  //  alert($location.path());

    var canvas   = document.getElementById('map'),
        defaults = { 
            center:    new google.maps.LatLng(0,0),
            zoom:      4,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };

    return {
        init:function(properties , scope) {
            mapPlacesGeocoder.getCoOrdinates(scope.address,function (coOrdinates) {
                var map=getMapObject.mapEntity();
             centerCoordinatesForMap.setMapObject(map);    
            var center = new google.maps.LatLng(coOrdinates.lat, coOrdinates.lng);
           centerCoordinatesForMap.setMapcenter(center);
              var circle=getMapObject.circleEntity();
              centerCoordinatesForMap.setCircleObject(circle);
                  var bounds = getMapObject.boundsEntity();
             centerCoordinatesForMap.setBoundObject(bounds);  

                var infoWindow = new google.maps.InfoWindow({       
                    boxStyle: {  
                        width: "0%",
                        backgroundColor:'#ccc'
                         }});


                 var icon = {        
                           url: "../img/square.png", // url
                           scaledSize: new google.maps.Size(10, 10), // scaled size
                           origin: new google.maps.Point(0, 0), // origin
                          anchor: new google.maps.Point(0, 0) // anchor
                            };  

                var markerCenter = new google.maps.Marker({           
                     draggable: true,
                     title: 'Drag me!',
                      map: map, 
                      position:center
                     });



       var sizer = new google.maps.Marker({       
           draggable: true,
            title: 'Drag me!',
            position:circle.getBounds(),
            map: map
            }); 




               circle.bindTo('center', markerCenter, 'position');

        google.maps.event.addListener(markerCenter, 'dragend', function() {
        latLngCenter = new google.maps.LatLng(markerCenter.position.lat(), markerCenter.position.lng());
        bounds = circle.getBounds(); 

        console.log(markerCenter.position.lat());
                console.log(markerCenter.position.lng()); 
        console.log(circle.getRadius());

             });

                for (var i = 0, length = properties.length; i < length; i++) {

                    var latLng = new google.maps.LatLng(properties[i].property_latitude, properties[i].property_longitude);

                    // Creating a marker and putting it on the map
                    scope.marker = new google.maps.Marker({ 
                        position:latLng,
                        map: map,
                      /*  icon:{
                             url:"/img/marker.jpg",
                            size: new google.maps.Size(80,80),
                            origin: new google.maps.Point(0, 0),
                            anchor: new google.maps.Point(24 / 2,24 / 2),
                            scaledSize: new google.maps.Size(40, 80)
                            }*/
                           });

                    bounds.extend(scope.marker.position);

                    google.maps.event.addListener(
                        scope.marker,
                        'mouseover',
                        (function( marker , scope, property,compile,location){
                            return function(){
                                var content = '<div id="google-popup">' +
                                    '<div class="infoWindowContent">' +property.hp_location.location_name +'</div>'+
                                    '<div class="infoWindowContent" ng-click="projectGallery()">' + property.hp_city.city_name +'</div>'+
                                    '<a  href=#'+location.path()+'?property_id='+property.propertyId+' class="active">' + property.property_name +'</a>' + '</div>';

                                var compiled = compile(content)(scope);
                                scope.$apply();
                                infoWindow.setContent(compiled[0].innerHTML);
                                infoWindow.open( Map , marker );
                             };
                        })(scope.marker,scope,properties[i],$compile,$location)
                     ); 


                     if(scope.city==true) {
                         circle.setMap(null);
                         map.fitBounds(bounds);
                        }
                      else if(scope.city==false) {
                         map.fitBounds(circle.getBounds());

                        }  

                    var listener = google.maps.event.addListener(map, "idle", function() {
                        google.maps.event.removeListener(listener);

                     });   


                    var listenerdragstart = google.maps.event.addListener(map, "zoom_changed", function() {

                        google.maps.event.clearListeners(map, 'idle');
                        google.maps.event.removeListener(listenerdragstart);
                    });


                    }

           })
        }//init
    };//return

});//

我必须设置此标记的此位置以在该圆的轮廓上创建什么?

google.maps.marker的
position
属性应为
google.maps.LatLng
而不是
google.maps.LatLngBounds
返回的
circle.getBounds()
类型

但是,可以获得边界的东北角和西南角的坐标。在你的例子中,你能做的是得到东北角的经度,得到圆的最右边的点,并将它设置为圆的中心纬度。这样,生成的位置将位于右侧圆的边界上

那么,你可以这样做:

position: new google.maps.LatLng(circle.getCenter().lat(), circle.getBounds().getNorthEast().lng()),

相关问题可能重复:相关问题:那更复杂。自己尝试一下,如果你被卡住了,就提出一个新问题。或者,您可以按照用户geocodezip指出的其他SO答案,例如,他们创建的这个答案:
position: new google.maps.LatLng(circle.getCenter().lat(), circle.getBounds().getNorthEast().lng()),