How to collect all latitude and longitude from foreach loop on one variable after loop finish?

22 views
Skip to first unread message

ahmed elbarbary

unread,
Dec 31, 2019, 2:11:13 AM12/31/19
to Angular and AngularJS discussion

How to collect all latitude and longitude from foreach loop on one variable after loop finish ?


   

 lati: string;  



    longi
: string;

   
this.partDetailsService.getLocationData(locationArr).subscribe(res => {                                          

    res
.forEach((item, index) =>

   
{

   
var dataLocation = res[index]['_source']['GPS1'];                      

   
var loc = dataLocation.split(',');  

   
this.lati = loc[0].trim(); //return 50  

   
this.longi = loc[1].trim(); // return 100  

     
});  


 


collectionlnglat =  



52,70  

30,40  

20,60  

50,100


collectionlnglat is variable store collect latitude,longtude from foreach


How to store all latitude and longtude for every iteration on variable collectionlnglat ?


first iteration 52,70


second iteration 30,40


third iteration 20,60


four iteration 50,100


collectionlatlng = 52,70 30,40 20,60 50,100

Manjari Singh

unread,
Dec 31, 2019, 2:23:28 AM12/31/19
to ang...@googlegroups.com
I think you can use arrays, with the same index

--
You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/angular/6167f61a-06ca-4daf-9f3c-be0fb00e25f6%40googlegroups.com.
--
Sent from Gmail Mobile

ahmed elbarbary

unread,
Dec 31, 2019, 2:40:31 AM12/31/19
to Angular and AngularJS discussion
can any one help me if possible on that

Manjari Singh

unread,
Dec 31, 2019, 5:38:25 AM12/31/19
to ang...@googlegroups.com
Declare a variable say “arr”  String[] type outside forEach, then inside forEach, refer arr[index]= “23,45” etc

On Tue, 31 Dec 2019 at 1:10 PM, ahmed elbarbary <ahmedsa...@gmail.com> wrote:
can any one help me if possible on that

--
You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.

Sander Elias

unread,
Dec 31, 2019, 1:06:51 PM12/31/19
to Angular and AngularJS discussion

would that work for you?
Reply all
Reply to author
Forward
0 new messages