加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – 纬度数组和经度映射

发布时间:2020-12-17 07:12:16 所属栏目:安全 来源:网络整理
导读:在我的项目中,我有一个包含纬度和经度列表的数据库,对应于几个地址,我想从这个数据库中获取它们并使用Angular 2在Google Maps中绘制它们(带路径). 但是,我陷入了这个问题.我没有输出.我的代码看起来像这样. 服务组件看起来像这样. import { Injectable } fro
在我的项目中,我有一个包含纬度和经度列表的数据库,对应于几个地址,我想从这个数据库中获取它们并使用Angular 2在Google Maps中绘制它们(带路径).
但是,我陷入了这个问题.我没有输出.我的代码看起来像这样.

服务组件看起来像这样.

import { Injectable } from '@angular/core';
import {Http,Response,Headers,RequestOptions} from "@angular/http";
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';

@Injectable()
export class HawkerserviceService{

baseUrl: string;
  constructor(private http: Http) {


   }
   fetchNews(): Observable<any> {

        return this.http.get('assets/data/locations.json')
                            .map(response => response.json());
   }


    }

我在家庭组件中调用它,看起来像这样

import { Component,OnInit } from '@angular/core';
import {Observable} from 'rxjs/Rx';

import {HawkerserviceService } from '../hawkerservice.service';


@Component({
  selector: 'app-home',templateUrl: './home.component.html',styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
  public latitude: number;
  public longitude: number;
    public places: any[];

  constructor( private hawkerservice: HawkerserviceService) { }

  ngOnInit() {

    this.hawkerservice.fetchNews()
    .subscribe(
    data=> {this.places= data.locations},Error=> console.log('this.places')
    );

  }

}

我的HTML组件是

<li *ngFor="let location of places>

 <sebm-google-map [latitude]={{location.latitude}}
[longitude]={{location.longitude}}>
  <sebm-google-map-marker  [latitude]={{location.latitude}}
[longitude]={{location.longitude}}></sebm-google-map-marker>
</sebm-google-map> 


</li>

但我没有得到任何输出.

我的JSON数据看起来像这样

{
    "locations": [

        {
            "title": "Sangam Chowk","latitude": 27.692612,"longitude": 85.342982
        },{
            "title": "Kharikobot","latitude": 27.690227,"longitude": 85.342671
        },{
            "title": "Ace Instute Of management","latitude": 27.690693,"longitude": 85.339581
        }
 ]
}

做这个的最好方式是什么?

解决方法

确保路径.尝试使用类似’./assets/data/locations.json’的方式更改路径字符串(注意./)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读