I am using google map in angular project (ngx-google-places-autocomplete and angular/google-maps
). Functionality is like user can select location and its latitude and longitude gets store. Now depending on lat, long stored, I need to display google map and marker on that co-ordinates.
HTML
<google-map
width="400px"
height="280px"
[zoom]="zoom"
[center]="initialCoordinates"
[options]="mapConfigurations">
</google-map>
ts
export class SampleComponent implements OnInit {
myDetails: any = [];
mylat: string = "51.076101702905575"; // default lat
mylong: string = "10.867780927493548"; // default long
zoom = 12;
initialCoordinates = {
lat: +this.myLat,
lng: +this.myLong,
};
mapConfigurations = {
disableDefaultūI: true,
fullscreenControl: true,
zoomControl: true,
mapTypeId: "roadmap",
scrollwheel: false,
disableDoubleClickZoom: true,
};
ngOnInit(): void {
this.getDetails();
}
getDetails() {
this.myService.getDetails(this.formData).subscribe((data) => {
if (data["status"] === false) {
} else {
this.myDetails = data["data"];
this.myLat = this.myDetails.latitude;
this.myLong = this.myDetails.longitude;
}
});
}
}
Above code displays map with default lat, long set everytime. myLat, myLong
variables always takes that default values. It does not overwrites with database values which I am setting in getDetails
function. As a beginner to angular, I am not sure how I can achieve that.
How I should set database fetched lat, long to google map and show marker on that?
please help and guide.