저는 TypeScript를 배우고 있습니다. 내 위치를 얻고 Googlemap API를 사용하여 거리와 도시에 대한 정보를 얻고 싶을 때 해결할 수없는 문제가 있습니다. 항상 말했습니다. 그 재산의 'str'을 읽을 수 없다 ... 나는 왜 그런지 모르겠다. 누군가 나를 도울 수 있습니까?null 형식의 'str'속성을 읽을 수 없습니다.
import { Component, OnInit } from '@angular/core';
import {Http, Response} from '@angular/http';
import 'rxjs/Rx';
import {Observable} from 'rxjs/';
@Component({
selector: 'app-center',
templateUrl: './center.component.html',
styleUrls: ['./center.component.css']
})
export class CenterComponent implements OnInit {
dataSource: Observable<any>;
locationInfo: any;
str: any;
constructor(public http: Http) {
this.dataSource = this.http.get('https://maps.googleapis.com/maps/api/geocode/json?'
+ 'latlng=' + this.str + '&key=AIzaSyC2wdo6kMAXpuhwuUa8fM4mCkDy_kZeWKY').map(Response => Response.json());
}
ngOnInit() {
}
getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(this.showPostion, this.showError);
}
}
showPostion(position) {
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
this.str.bind(this);
this.str = String(latitude + ',' + longitude);
console.log(this.str);
}
showError() {
console.log('Invalid Address !');
}
getData() {
this.dataSource.subscribe(
data => this.locationInfo = data
);
console.log(this.locationInfo);
}
}
당신의 스택 트레이스를 제공 할 수 바인딩해야 문제가 어디에서 발생 했습니까? – JamesFaix