2

First of all I'm using Angular Google Map (ng-map). I want to get clicked location of google map's latitude and longitide.

My Code

<ng-map center="[{{latitude}}, {{longitude}}]">
   <marker position="[{{latitude}}, {{longitude}}]" title="how" animation="Animation.BOUNCE"></marker>
</ng-map>
White Marcus
  • 195
  • 2
  • 3
  • 12

3 Answers3

3

You could do that this way, and also could get the coordinates even on marker drag:

<ng-map on-click="getpos($event)">
    <marker ng-repeat="p in positions" 
      position="{{p}}" on-dragend="getpos($event)">
    </marker>
</ng-map>

and in your controller:

$scope.getpos = function(event) {
    console.log(event.latLng);
};

Fiddle: fiddle

Update: with initialize

Edit I would try

changing your js

app.run(function(editableOptions) {
    editableOptions.theme = 'bs3';
});

into

app.run(function(editableOptions, $rootScope) {
    editableOptions.theme = 'bs3';
    $rootScope.$on('mapInitialized', function(evt,map) {
        $rootScope.map = map;
        $rootScope.$apply();
    });
});
daniel
  • 1,152
  • 2
  • 15
  • 33
  • Great, mark it as an answer then. :P... it should... something else is not working... create a fiddle. – daniel Mar 15 '16 at 08:43
  • https://ngmap.github.io/#/!marker-animations.html => view this page. My project also like this. – White Marcus Mar 15 '16 at 08:51
  • In fact that is on dragevent... and you could use *$scope.getpos()* function... see the fiddle for the ng-map on-click. – daniel Mar 15 '16 at 09:02
  • Oh God..! In this map have the problem. In angular single page application this perfectly works for first time on page loading. After that its not works. only blank screen relies. How can i remove cache without page reload. Help me daniel. – White Marcus Mar 16 '16 at 12:14
  • I don't understand what is happening... can you show this in a fiddle? – daniel Mar 16 '16 at 15:46
  • http://rotary3230.in/15-16/business_dir/#/business_details/1 This is my page. Below in the location tab there is two locations (Valasaravakkam, test). After page load completion click any one's view map (It works perfectly). but the another one shows blank map. and also in the vise versa. – White Marcus Mar 17 '16 at 05:46
1

To initialize in google maps:

var latlngbounds = new google.maps.LatLngBounds();
google.maps.event.addListener(map, 'click', function (e) {
alert("Latitude: " + e.latLng.lat(); + "\r\nLongitude: " + e.latLng.lng());
Kory Gill
  • 6,993
  • 1
  • 25
  • 33
0

For that you have to set one function on map click like

<ng-map center="[{{lat}}, {{lng}}]"  zoom-to-inculude-markers="auto" on-click="getCurrentLocation($event)">
        <marker position="{{latlng}}"></marker>
    </ng-map>

on your controller.js file you can set lat long like this

$scope.getCurrentLocation = function(event){

        console.log(event.latLng.lat());
        console.log(event.latLng.lng());
    }

Hope This will help you.

Shiv
  • 26
  • 8