How to return value of Longitude and latitude for GPS1 from json using angular 7? RRS feed

  • Question

  • User696604810 posted

    How to return value of longtide and latitude from json using angular 7?

    my url as following :


    json returned from url above is :

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

    longtiude : 25.0173

    latitude : 121.462

    Based on LocationId parameter :27737

    So that I need to create service

    and How to call on ngoninit

    on ngOinInit Event

    How to create service then call it on ngOnInit

    call service here

    Saturday, December 28, 2019 6:55 PM


  • User-1780421697 posted

    _source.GPS1 will give you ["25.0173, 121.462"], its an array, will give you lat and long, here is https://angular.io/tutorial/toh-pt4 to create service. it also defined how to call service in 

    ngOnInit() { this.yourServiceName(); }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 20, 2020 6:01 AM