angular - 无法在 getCurrentPosition 函数上获取简单成功回调的坐标
问题描述
getUserLocation() 和 if 语句一样触发。navigator.geolocation.getCurrentPosition() 函数不会触发。我无法在该声明中记录任何内容。我不知道为什么什么也没发生..
只需登录箭头功能。那里什么也没有显示。
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'google-map',
templateUrl: './google-map.component.html',
styleUrls: ['./google-map.component.css']
})
export class GoogleMapComponent implements OnInit {
lat: number;
lng: number;
constructor() { }
ngOnInit() {
this.getUserLocation();
}
getUserLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition( position => {
this.lat = position.coords.latitude;
this.lng = position.coords.longitude;
});
}
}
}
我需要 lat/lng 的值。
解决方案
推荐阅读
- java - 如何使 maven-surefire-plugin 重用创建的线程来执行所有 Maven 模块中的所有测试
- python - 如何使用 python 访问 Tableau 2020.2 中的 bin 目录并使用 tableau 实用程序命令行自动更新数据连接
- excel - 在 Excel 中为条形图创建辅助轴
- sql - 在雪花中旋转多个列
- realm - 尝试使用 Keycloak 实现 OpenId Connect,但我总是得到“代码无效”
- java - Java 使用 LocalDateTime 0000-00-00 00:00:00 解析 JSON
- java - Java 扫描仪错误:java.util.NoSuchElementException:找不到行 -- java.base/java.util.Scanner.nextLine(Scanner.java:1651))
- c# - 需要帮助制定英里步行计划
- c# - 正则表达式 - 如何匹配块注释
- sql-server - T-SQL 获取给定组的最后一个值