首先,我使用Angular Google Map(ng-map)。我希望点击谷歌地图的纬度和长度的位置。
我的代码
<ng-map center="[{{latitude}}, {{longitude}}]">
<marker position="[{{latitude}}, {{longitude}}]" title="how" animation="Animation.BOUNCE"></marker>
</ng-map>
答案 0 :(得分:3)
你可以这样做,甚至可以在标记拖动时获得坐标:
<ng-map on-click="getpos($event)">
<marker ng-repeat="p in positions"
position="{{p}}" on-dragend="getpos($event)">
</marker>
</ng-map>
并在您的控制器中:
$scope.getpos = function(event) {
console.log(event.latLng);
};
小提琴: fiddle
更新: with initialize
修改我会尝试
更改你的js
app.run(function(editableOptions) {
editableOptions.theme = 'bs3';
});
进入
app.run(function(editableOptions, $rootScope) {
editableOptions.theme = 'bs3';
$rootScope.$on('mapInitialized', function(evt,map) {
$rootScope.map = map;
$rootScope.$apply();
});
});
答案 1 :(得分:1)
要在Google地图中初始化:
var latlngbounds = new google.maps.LatLngBounds();
google.maps.event.addListener(map, 'click', function (e) {
alert("Latitude: " + e.latLng.lat(); + "\r\nLongitude: " + e.latLng.lng());
答案 2 :(得分:0)
为此,您必须在地图上设置一个功能,例如单击
<ng-map center="[{{lat}}, {{lng}}]" zoom-to-inculude-markers="auto" on-click="getCurrentLocation($event)">
<marker position="{{latlng}}"></marker>
</ng-map>
在controller.js文件中,您可以像这样设置lat
$scope.getCurrentLocation = function(event){
console.log(event.latLng.lat());
console.log(event.latLng.lng());
}
希望这会对您有所帮助。