小编pra*_*bin的帖子

纬度数组和经度映射

在我的项目中,我有一个包含纬度和经度列表的数据库,对应于几个地址,我想从这个数据库中获取它们并使用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());
   }


    }  
Run Code Online (Sandbox Code Playgroud)

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

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; …
Run Code Online (Sandbox Code Playgroud)

angular2-template angular2-services angular

6
推荐指数
1
解决办法
2239
查看次数