0

I'm trying to build an Angula2 application,I want to get the position(longitude and latitude) when i click on a point in the map to be able to insert those fields in my database. Here is the Map code:

<sebm-google-map [latitude]="lat" [longitude]="lng" [zoom]="zoom" [backgroundColor]="backgroundColor" >
  <sebm-google-map-marker *ngFor=" let post of posts" [latitude]="post.lapti" [longitude]="post.longi" ></sebm-google-map-marker>
</sebm-google-map>

Any solution?

1 Answer 1

2

You have the mapclick event :

<sebm-google-map (mapClick)="getPosition($event)" [latitude]="lat" [longitude]="lng" [zoom]="zoom" [backgroundColor]="backgroundColor" >
  <sebm-google-map-marker *ngFor=" let post of posts" [latitude]="post.lapti" [longitude]="post.longi" ></sebm-google-map-marker>
</sebm-google-map>

...

getPosition(event: MouseEvent ) {
  let coords: LatLngLiteral = event.coords; //coords.lat, coords.lng are numbers
  console.log(coords.lat); //the clicked point latitude
  console.log(coords.lng); //the clicked point longitude
    ...
}

Plunker here : http://plnkr.co/edit/UWl3Tm

Sign up to request clarification or add additional context in comments.

8 Comments

Can you explain more what i should write in the getPosition function?
I add console.log, is it better or am I missing the sens of your question ?
it says that property coords does not exist on type MouseEvent
Is your MouseEvent imported from here : github.com/SebastianM/angular-google-maps/blob/… ?
No,I should add those 2 lines in app-module,or install it with npm?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.