ahmed elbarbary

ahmed elbarbary

  • NA
  • 1.6k
  • 278.4k

How to display more than locaions gps on googlemap?

Dec 30 2019 6:18 AM
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);
 
  1. this.partDetailsService.getLocationData(locationArr).subscribe(res => {    
  2.                  console.log(res);  
  3.          res.forEach((item, index) => {  
  4.              let dataLocation = res[index]['_source']['GPS1'];    
  5.              console.log(dataLocation);     
  6.              let loc = dataLocation.split(',');     
  7.              console.log("After");    
  8.              console.log(loc);            //show latitude,longtude separated comma  
  9.              console.log(loc[0].trim()); //show latitude  
  10.              console.log(loc[1].trim()); //show Longtude  
  11.      
  12.               
  13.           });  
  14.             
  15.         //=======================================================  
  16.   
  17.          
  18.       How to pass values of loc[0].trim() and loc[1].trim() result of foreach loop  
  19.         const coordinates = new google.maps.LatLng(collection of lat result of foreach loop, collection of lng result of foreach loop);  
  20.           const mapOptions: google.maps.MapOptions = {  
  21.             center: coordinates,  
  22.             zoom: 8  
  23.           };  
  24.         
  25.           const marker = new google.maps.Marker({  
  26.             position: coordinates,  
  27.             title: 'Hello World!'  
  28.           });  
  29.         
  30.           const map = new google.maps.Map(this.gmap.nativeElement, mapOptions);  
  31.           marker.setMap(map);  
  32.         }         
  33.         );          
  34.       
  35.         //=================================  
  36.          
  37.       }  
  38. onManagelocations.component.html  
  39. <div #mapContainer id="map"></div>  
 

Answers (1)