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.
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 ...
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 ...
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 ...
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 ...