如何从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
}
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};
});
}