我想用标记填充Google地图。
我得到的标记坐标为String:
"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方法:
/**
* Bad workaround for markers
*/
private createSources(result): void {
this._sources = result;
let sourceLat: number, sourceLng: number;
this.positions = [];
let latlong = null;
for (let i = 0; i < this._sources.length; i++) {
sourceLat = +this._sources[i].marker.latitude;
sourceLng = +this._sources[i].marker.longitude;
// Create position object
latlong = { lat: sourceLat, lng: sourceLng };
this.positions.push([this._sources[i].id, latlong]);
}
}
Angular的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 :(得分:0)
尝试
[position]="+marker.latitude, +marker.longitude"
基本JS转换