I have foreach loop it loop to all locations and get gps location latitude and longtude of GPS1 and display it on google map
I need to collect all latitude and longtude from foreach loop then pass it to function LatLng
const coordinates = new google.maps.LatLng(values of lat , values of lng);
- this.partDetailsService.getLocationData(locationArr).subscribe(res => {
- console.log(res);
- res.forEach((item, index) => {
- let dataLocation = res[index]['_source']['GPS1'];
- console.log(dataLocation);
- let loc = dataLocation.split(',');
- console.log("After");
- console.log(loc); //show latitude,longtude separated comma
- console.log(loc[0].trim()); //show latitude
- console.log(loc[1].trim()); //show Longtude
- });
- //=======================================================
- How to pass values of loc[0].trim() and loc[1].trim() result of foreach loop
- const coordinates = new google.maps.LatLng(collection of lat result of foreach loop, collection of lng result of foreach loop);
- const mapOptions: google.maps.MapOptions = {
- center: coordinates,
- zoom: 8
- };
- const marker = new google.maps.Marker({
- position: coordinates,
- title: 'Hello World!'
- });
- const map = new google.maps.Map(this.gmap.nativeElement, mapOptions);
- marker.setMap(map);
- }
- );
- //=================================
- }
- onManagelocations.component.html
- "map">
ammar zaidiPosted Jan 3, 2020, 1:04 AM