JavaScript Angular 2, subscribe when coordinates are received angular subscribe when to unsubscribe,angular subscribe when done,angular

I'm learning Angular 2. I'm using a LocationService with an Observable that hands me the coordinates after some time. This is my code.

location.service.ts

public getLocation(): Observable<any> {
    return Observable.create(observer => {
        if(window.navigator && window.navigator.geolocation) {
            window.navigator.geolocation.getCurrentPosition(
                (position) => {
                    observer.next(position);
                    observer.complete();
                },
                (error) => observer.error(error)
            );
        } else {
            observer.error('Unsupported Browser');
        }
    });
}

app.component.ts

ngOnInit() {
    this.location.getLocation().subscribe((coordinates) => {
        this.lat = coordinates.coords.latitude;
        this.lng = coordinates.coords.longitude;
    });
}

How can I subscribe to the receiving of the coordinates so I can render a map, add a marker, .. once I receive them from the first subscribe.

Answer:1

I'm new to js/programming and just making a simple calculator using prompt. I'm trying to validate that what's been entered are numbers and not strings. I tried this var operatorType = prompt("Do ...

I'm new to js/programming and just making a simple calculator using prompt. I'm trying to validate that what's been entered are numbers and not strings. I tried this var operatorType = prompt("Do ...

  1. if/else statement java
  2. if/else statement python
  3. if/else statement c++
  4. if/else statement javascript
  5. if/else statement code.org
  6. if/else statement r
  7. if/else statement excel
  8. if else statement
  9. if else statement in c
  10. if else statement java
  11. if else statement python
  12. if else statement in c example
  13. if else statement excel
  14. if else statement in r
  15. if else statement javascript
  16. if else statement example
  17. if else statement matlab
  18. if else statement in sql
  19. if else statement java exercises
  20. if else statement arduino

I have an AngulaarJS application where users select the day they want to view and it prints on the calendar the day and the next 30 days. The intended functionality needs to be so that when a user ...

I have an AngulaarJS application where users select the day they want to view and it prints on the calendar the day and the next 30 days. The intended functionality needs to be so that when a user ...

  1. how to get current date in angularjs
  2. angularjs add days to current date

I would like to get a list of all the properties, styles, events and methods of an HTML element. Is there a reflection API in the browsers? I'm looking for something like this: var button = new ...

I would like to get a list of all the properties, styles, events and methods of an HTML element. Is there a reflection API in the browsers? I'm looking for something like this: var button = new ...

  1. does javascript run in browser or server
  2. does javascript run in browser

My function is like below. Consider for high performance, how can I avoid to add text in a loop structure in html? Please advise. Thank you so much. function createDiv (array) { var i; var ...

My function is like below. Consider for high performance, how can I avoid to add text in a loop structure in html? Please advise. Thank you so much. function createDiv (array) { var i; var ...