Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to return value of longitude and latitude from json using angular 7?

my URL as following :

http://192.168.7.xxx:9200/location/_doc/27737

json returned from url above is :

CSS
{"_index":"location","_type":"_doc","_id":"27737","_version":1,"_seq_no":5577,"_primary_term":1,"found":true,"_source":{"Locid":27737,"GPS1":"25.0173, 121.462","GPS2":"25°01'02.2\"N 121°27'44.8\"E","CompanyID":1005070,"ads":"142 Sec. 1, HsIn Nan Rd cung Ko Dšst, New Taipei City, Taiwan","Crid":75,"con":"Taiwan","Ctid":5894,"Cn":"Zhonghe District","pushdate":"2019-12-26T03:38:20.883"}}


I need to return two values from GPS1 :

longitude : 25.0173

latitude : 121.462

Based on LocationId parameter :27737

So that I need to create service

take location id parameters

and return two values of GPS1
longitude
And
latitude

then set values returned of longtude and latitude

on ngOinInit Event

How to create service then call it on ngOnInit

CSS
ngOnInit  
{  
call service here  
}


What I have tried:

getDataService(): Observable<any> {    
     const url = "http://xxx.xxx.4.xxx:9200/pcn/_search";    
       return this.httpClient.get(`${url}`);    
   }  
Posted
Updated 3-Jan-20 17:25pm

1 solution

Your service is returning the values. You just need to parse them out of the strings. You can split a string on a , to create an array of values
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900