2017-07-11 19 views
-1

Googleマップにマーカーを設定したいと思います。マーカー座標「文字列」値を数値に変換する

は、私は文字列として取得:

"marker": { 
     "latitude": "52.31976", 
     "longitude": "7.00454" 
} 

JSONを取得するための私のサービス:

/** 
    * Get All Sources 
    */ 
    getSources(): Observable<Source.RootObject[]> { 
     return this._http.get(this._sourceUrl) 
      .map((response: Response) => <Source.RootObject[]>response.json()); 
    } 

コールを処理する私のコンポーネント:

/** 
    * Set local _sources array equal data from stream 
    * @param _sourceService 
    * @param router 
    */ 
    constructor(
     private _sourceService: SourceService, 
     private router: Router 
    ) { 
     this._sourceService.getSources() 
      .subscribe(_sources => this.createSources(_sources)); 
    } 

createMArkers方法:

012角度付き

HTMLマークアップ:

<ngui-map zoom="8" center="{{center}}" > 

    <marker *ngFor="let pos of positions" 
       [icon]="{ 
       url: 'assets/icons/marker.svg', 
       anchor: [16,16], 
       size: [32,32], 
       scaledSize: [32,32] 
      }" 
      (click)="printLog(pos)" 
      [position]="pos.latlong"></marker> 
    </ngui-map> 

私は位置のために別々の配列を作成しますが、単にソースオブジェクトの配列を使用したくない(例えば、 source.marker.longitude)

は、私が試した:それは文字列値ですので

  • [position]="marker.latitude, marker.longitude"は受け付けられません。
  • [position]=marker.latitude, marker.longitudeキャストされることを希望します。事前に
  • [position]={{marker}}

感謝。

+0

@toskvの活字体とを

[position]="+marker.latitude, +marker.longitude" 

基本JS変換を試してみて、どのように角度でこれを解決するために? – Lobato

+1

あなたはサーバーからの応答を処理すると同時にjavascriptで変換を行うことができます。 – toskv

+0

あなたは正しい方向に私を向けることができます..? – Lobato

答えて

0

はcomponent.tsに

+0

パーサーエラー:[+マーカー内の列24に予期しないトークン '、'があります。緯度、マーカ、緯度] [ERROR - >] [position] = "+ marker.latitude、+ marker.longitude" – Lobato

+0

これは '[position] =" marker.latitude、marker.longitude "あなたがこのエラーを受けなかったか、あなたの投稿に間違いがありました! – trichetriche

+0

同じエラーです。正確にはどういう意味ですか? – Lobato

関連する問題