- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试在我的 ionic2 hello world 项目中使用地理定位,并且我按照 official site 上的说明添加了 ionic 插件“Geolocation” .
我已经运行了这两个命令:
$ ionic plugin add cordova-plugin-geolocation
$ npm install --save @ionic-native/geolocation
这是我的家.ts:
import { Component } from '@angular/core';
import {Geolocation} from '@ionic-native/geolocation'
import { NavController } from 'ionic-angular';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
map:any=null;
geoInfo:any={
resp:'',
data:''
};
constructor(
public navCtrl: NavController,
private geolocation: Geolocation
) {
}
test(){
this.geolocation.getCurrentPosition().then((resp) => {
this.geoInfo.resp=JSON.stringify(resp);
// resp.coords.latitude
// resp.coords.longitude
}).catch((error) => {
console.log('Error getting location', error);
this.geoInfo.resp='Error getting location';
});
let watch = this.geolocation.watchPosition();
watch.subscribe((data) => {
this.geoInfo.data=JSON.stringify(data);
// data can be a set of coordinates, or an error (if an error occurred).
// data.coords.latitude
// data.coords.longitude
});
}
}
但是,我的 chrome 控制台出现以下错误:
EXCEPTION: Error in ./TabsPage class TabsPage - inline template:0:0 caused by: No provider for Geolocation!
error_handler.js:56ORIGINAL EXCEPTION: No provider for Geolocation!
起初我以为是因为我在浏览器中调试,但后来我的 Android 手机出现了同样的错误。
那么“No provider for Geolocation”是什么意思,我应该如何在我的 ionic2 项目中使用地理定位?
非常感谢!
最佳答案
你需要在 NgModule 中添加 provider,即 providers 下的 module.ts,
providers: [
Geolocation
]
关于angular - ionic 地理定位插件错误 : "No provider for Geolocation",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42993045/
我正在编写需要获取设备位置的 Windows Phone 8 应用(不跟踪更改,只获取位置)。我在起始页的 OnNavigatedTo() 方法中添加了下一个代码,但在启动应用程序后,进度指示器即使在
工作灯 6.2.0.00-20120814-0824 位置代码在浏览器模拟器中运行良好,但在 Android 模拟器中失败,成功或失败回调均未触发。 Logcat 显示: 10-06 16:00:40
我向 google geolocation api 发送了两个请求:https://www.googleapis.com/geolocation/v1/geolocate?key=[mykey] 第一
Type 'GeolocationOriginal' is not assignable to type 'Provider'. Type 'GeolocationOriginal' is missi
我正在开发一个带有谷歌地图的网络应用程序,并使用 getCurrentPosition() 获取用户位置。这很好用,但我需要随着时间的推移跟踪用户位置。 为此,我打算使用 watchPosition(
我正在尝试搜索一个地址,然后尝试通过 Geolocator 获取该位置的位置,然后尝试将相机位置设置到该位置,但它不起作用。 我发现了 Geolocator 的两种方法的一些异常(exception)
我在 Windows 商店单元测试项目中进行了此单元测试,使用 this overload of GetGeopositionAsync地理定位器: [TestMethod] public async
这是我的情况;我构建了一个非常简单的网络应用程序,用于查找用户位置并将其绘制在 Google map 上。这是我的代码:http://pastebin.com/d3a185efd 当我测试它时,我的位
我有一个表,其中包含位置列数据作为经纬度信息,如何获取多边形内位置的记录 多边形点 [ [42.811521745097906, -105.60058593749999], [33.9
获取网络请求来源位置(国家级别)的最佳方式是什么? 最佳答案 一般来说有3种方式: 使用 GeoIP 或将 IP 映射到物理位置的一些类似数据库或服务 使用 W3C 地理定位 API(仅受较新的浏览器
我们一直需要为我们的一些产品实现一些地理定位服务集成。有很多 3rd 方公司提供免费和付费的地理位置服务和数据库,这些服务和数据库有时会不断更新,有时会每月更新一次。 这些服务从哪里获得他们分发的数据
如何使用经度和纬度找到最近的机场? 任何特定的网络服务和任何数据库来实现? 最佳答案 我发现的一个 WebService 是 airport.pidgets.com 这是一个例子: XML 格式 ht
在许多网站上,我看到打印出我当前所在的城市(例如“Hello to Berlin.”)。他们是怎么做到的?为此需要什么? 我想主要部分是这里的 javascript,但是在我自己的应用程序中实现这样的
大家好, 我正在创建一个使用 Geolocation API 来定位最终用户的 Web 应用程序。它在我能想到的几乎所有平台上都运行良好,除了 Internet Explorer 9。不过事情变得有点
我目前正在使用“区域”示例代码: https://developer.apple.com/library/ios/#samplecode/Regions/Introduction/Intro.h tm
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 3年前关闭。 Improve thi
我在筛选 twitter API 时遇到了一些麻烦。我正在尝试搜索某个位置附近的推文,然后查看它们的精确(或近似)地理坐标。我知道 geo 字段已被弃用,现在我们应该使用“place”字段。不幸的是,
我需要能够评估一个位置的地理坐标有多远。我根据几个关键指标对远程度进行评分,到目前为止,我只能计算所有必需指标的一个子集: 给定坐标处的蜂窝接收。更具体地说,坐标周围的蜂窝塔密度。这可以使用 open
我正在开发GeoTargeting应用程序。我很好奇地球上某个点的经度和纬度是否可以改变? 如果您知道自由女神像的确切位置,那么如何确定经度和纬度将保持不变。 它是根据季节,一年中的时间还是随着时间的
由于Cassandra基于Dynamo纸(分布式,自平衡哈希表)+ BigTable,因此存在一些空间索引可以很好地适合该范式(quadkey或geohash)。是否有未实现地理空间支持的原因? 您可
我是一名优秀的程序员,十分优秀!