Html 转换;“字符串”;数值

Html 转换;“字符串”;数值,html,angular,typescript,google-maps-api-3,Html,Angular,Typescript,Google Maps Api 3,我想用标记填充谷歌地图 作为字符串获取的标记坐标: "marker": { "latitude": "52.31976", "longitude": "7.00454" } 检索JSON的我的服务: /** * Get All Sources */ getSources(): Observable<Source.RootObject[]> { return this._http.get(this._source

我想用标记填充谷歌地图

作为字符串获取的标记坐标:

"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());
    }
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]);
        }
    }
/**
*标记的错误解决方法
*/
私有createSources(结果):void{
这是._sources=结果;
设sourceLat:number,sourceLng:number;
这个。位置=[];
设latlong=null;
for(设i=0;i
带有角度标记的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}
提前谢谢。

试试看

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

基本JS转换

解析器错误:意外标记',[+marker.latitude,+marker.longitude][Error->][position]=“+marker.latitude,+marker.longitude”中第24列的“,”这就是你用
[position]=“marker.latitude,marker.longitude”
测试的内容,你没有得到这个错误,或者你在帖子中犯了一个错误!同样的错误,你的确切意思是什么?我从你的最后几行代码:
[position]=“marker.latitude,marker.longitude”
,你说你尝试了,但由于字符串值的原因无法工作。所以我问你,你将如何发送数据?我在
[position]使用坐标之前或使用坐标时,将坐标作为字符串值获取=“…
它们必须是converted@toskv这是component.ts中的TypeScript,但是如何用Angular解决这个问题呢?你可以在处理服务器响应的同时用javascript进行转换。你能给我指出正确的方向吗?/,或者对其执行数字操作。。。(但您必须分别对待每个数字)
[position]="+marker.latitude, +marker.longitude"