【发布时间】:2020-04-26 07:59:04
【问题描述】:
我想get 使用 AngularFire 使用包含 lat/lng 坐标的 URL 参数的 Firestore 中的特定文档,然后将这些坐标绑定到 google-map 组件的 [center] 属性,以根据哪个项目动态显示地图看过。但是数据没有连接到谷歌地图属性,所以它默认以谷歌总部位置为中心。
主组件 List 为 URL hike/:hikeId 中的事件传递一个 id,我提取该事件,然后使用 AngularFire 获取文档。
hike-detail.component.html
<h1>Hike Detail</h1>
<h3>Name: <span>{{ (hikeInfo | async)?.name }}</span></h3> // Displays Hike A
<google-map
[center]="hikeInfo.center | async"
width="100%">
</google-map>
hike-detail.component.ts
import { Component, OnInit, Input } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { Location } from '@angular/common';
import { AngularFirestore, AngularFirestoreDocument } from '@angular/fire/firestore';
import { Observable } from 'rxjs';
import { stringify } from 'querystring';
import { map } from 'rxjs/operators';
@Component({
selector: 'app-hike-detail',
templateUrl: './hike-detail.component.html',
styleUrls: ['./hike-detail.component.css']
})
export class HikeDetailComponent implements OnInit {
hikeId;
hikeInfo;
center: google.maps.LatLngLiteral;
constructor(
private route: ActivatedRoute,
private location: Location,
private router: Router,
private firestore: AngularFirestore
) { }
ngOnInit(): void {
this.hikeId = this.route.snapshot.paramMap.get('id');
this.hikeInfo = this.firestore.collection('hikes').doc(this.hikeId).valueChanges();
}
}
数据库
firestore
-- hikes
-- key
-- name: Hike A
-- center: {
lat: 28.12,
lng: 32.71
}
它目前显示名称和以通用 Google 总部为中心的 google 地图,也就是 [center] 绑定不起作用。
【问题讨论】:
标签: javascript angular firebase google-cloud-firestore angularfire