如何从json创建服务返回的经度和纬度值?

问题描述 投票:0回答:1

如何从JSON创建经度和纬度的服务返回值?

我有以下网址:

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

此URL JSON下面:

    {"_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"}}  

我需要从GPS1创建服务返回两个值:

longitude: 25.0173,
latitude: 121.462

基于位置Id参数27737

因此,我需要创建带有位置id参数的服务并返回GPS1 25.0173和25.0173的两个值

getDataService(locationid): Observable<any> {    
     const url = "http://192.168.7.xxx:9200/location/_doc/27737";    
       return this.httpClient.get(`${url} + locationid`);    
   }  

ngOinInit事件上

ngOnInit  
{  
call service here  
}  
javascript typescript angular7 angular-routing angular-resource
1个回答
0
投票
假设您在一个名为response的变量中返回了json。你可以做

getDataService(locationid): Observable<any> { const url = "http://192.168.7.xxx:9200/location/_doc/27737"; return this.httpClient.get(`${url} + locationid`) .then(response => { const [latitude, longitude] = response._source.GPS1.trim().split(","); return {latitude, longitude}; }); }

© www.soinside.com 2019 - 2024. All rights reserved.