0
こんにちは上のマップを描画するために私がグーグルを使用しています、すべてはnodejsクライアントのWeb APIをマッピングして、私はAngularJS 2.使用するGoogleマップNodeJSジオコードコールバック関数の結果はAngularJS 2コンポーネントテンプレート
を通じて私HTMLviewsに地図を表示したいと思います私AngularJS2クライアントサービスにオブジェクトを返します。このサーバーのエクスポートを持つAngular2サービスがこの
@Injectable()
export class MyService {
constructor(private http: Http) { }
getMessage(): Promise<mma> {
return this.http.get('/map-moving-agents')
.toPromise()
.then((res)=> {
console.dir(res.json().maps);
return res.json().obj;
})
.catch(this.handleError);
}
すべてのように見える
const googleMapsClient = require('@google/maps').createClient({
key: 'AIzaSyCYcyd0vCGRY6Pq5E0u_ECTFi4I9VmUE4o'
});
module.exports = (req, res) => {
googleMapsClient.geocode({
address: 'Cosmo City, Roodepoort USA street'
}, function(err,response) {
if(err) {
console.log("There was an error geocoding the address", err)
} else {
console.log("Here is the maps response", response.json.results)
var obj = {
name: "Thabo",
age: 23,
maps: response.json.results
};
res.json({obj});
}
});
}
サーバーから予期される応答が得られました。この応答を使用して、コンポーネントテンプレートにマップを描画したいと考えています。ここ
そして、私のAngularJS2コンポーネントは
ある@Component({
moduleId:module.id,
selector: 'map-moving-agents',
templateUrl: 'moving-agents.html',
styleUrls: ['moving-agents.css'],
providers: [ MyService ]
})
export class MapMovingAgents implements OnInit{
msg : mma;
constructor(private myService: MyService){}
getMessage(): void {
this.myService.getMessage().then((res) => {
this.msg = res;
console.log(this.msg.name);
})
}
ngOnInit(): void {
this.getMessage();
}
}