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}}
感謝。
@toskvの活字体とを
基本JS変換を試してみて、どのように角度でこれを解決するために? – Lobato
あなたはサーバーからの応答を処理すると同時にjavascriptで変換を行うことができます。 – toskv
あなたは正しい方向に私を向けることができます..? – Lobato