所以我有这个程序的角度在迄今为止,我在邮政编码从用户和按一下按钮就发,输入功能在那里被送到一个api转换成经纬度和长坐标。 见下文:
home.component.html
<div class="center" style="margin-top:50px;">
<label for="ZipCode"><b>Zip Code</b></label>
</div>
<div class="center">
<input name="zipcode" #zipcode id="zipcode" type="text" placeholder="Enter Zip Code" maxlength="5">
</div>
<div class="center" style="margin-top:100px;">
<button class="button button1" (click)="getCoords(zipcode.value)" ><b>Retrieve Data</b></button>
</div>
显然这只是一段代码,但它是不够显示目的。 接下来是功能与api和它然后转移查站的组件/page:
家。组成部分。ts
export class HomeComponent implements OnInit {
constructor(
private router: Router
){}
ngOnInit(): void {
}
getCoords(val: any){
var url = "http://www.mapquestapi.com/geocoding/v1/address?key=MYKEY&location=" + val;
fetch(url)
.then((res) => res.json())
.then((data) => {
var lat = data.results[0].locations[0].displayLatLng.lat;
var long = data.results[0].locations[0].displayLatLng.lng;
this.router.navigate(["/stations"])
})
}
}
站。组成部分。ts -你可以看到这里没有什么因为我不能找出什么做
import { Component, Input, OnInit } from '@angular/core';
@Component({
selector: 'app-stations',
templateUrl: './stations.component.html'
})
export class StationsComponent implements OnInit {
ngOnInit(): void {
}
}
现在,这一切正常工作。 我已经测试过的纬度和长期的变量控制记录和返回的纬度和长就好了。 我的问题是我需要送的纬度和长期价值的另一个组成部分/网页应使用在计算。 我不会撒谎说我已经走遍了因特网试图找到一种方法来这样做,但显然它并不是容易的角度这样做。 任何人有任何想法,通过纬度和长期价值的另一个组件/page?
dataLat: lat
和误差说:Argument of type '{ dataLat: any; dataLong: any; }' is not assignable to parameter of type 'NavigationExtras'. Object literal may only specify known properties, and 'dataLat' does not exist in type 'NavigationExtras'.