2017-03-24 11 views
16

मैं अपने आयनिक 2 हैलो वर्ल्ड प्रोजेक्ट में भौगोलिक स्थान का उपयोग करने की कोशिश कर रहा हूं, और official site पर निर्देश के बाद मैं आयनिक प्लगइन "जिओलोकेशन" जोड़ता हूं।आयनिक भौगोलिक स्थान प्लगइन त्रुटि: "जिओलोकेशन के लिए कोई प्रदाता नहीं"

मैं इन दोनों आदेशों को चलाने की है:

$ ionic plugin add cordova-plugin-geolocation 
$ npm install --save @ionic-native/geolocation 

और ये मेरे home.ts है:

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! 
:

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 
     }); 

    } 

} 

हालांकि, मैं अपने क्रोम के कंसोल में निम्न त्रुटि मिला

screenshot

पहले मैंने सोचा था कि ऐसा इसलिए था क्योंकि मैं ब्राउज़र में डिबगिंग कर रहा था, लेकिन फिर मुझे अपने एंड्रॉइड फोन में एक ही त्रुटि मिली।

तो "भौगोलिक स्थान के लिए कोई प्रदाता" का अर्थ क्या नहीं है और मुझे अपने आयनिक 2 प्रोजेक्ट में भौगोलिक स्थान का उपयोग कैसे करना चाहिए?

बहुत बहुत धन्यवाद!

उत्तर

34

आप प्रदाता NgModule को प्रदाताओं के तहत, यानी module.ts जोड़ने के लिए,

providers: [ 
    Geolocation 
] 
+0

'app.module.ts' में जिओलोकेशन जोड़ने के बाद, मुझे एक नई त्रुटि मिली:' अनकही संदर्भ त्रुटि: जिओलोकेशन परिभाषित नहीं किया गया है '। – awmleer

+2

वर्तनी के लिए जाँच करें Geolocationa – Sajeetharan

+0

क्षमा करें, मैंने ऐसी मूर्खतापूर्ण गलती की है ... – awmleer

2

जरूरत है आप जियोलोकेशन वर्ग आयात और app.module.ts में प्रदाताओं की अपनी सूची में जोड़ने की जरूरत फ़ाइल

import { Geolocation } from '@ionic-native/geolocation'; 

providers: [ 
    Geolocation 
] 
0

है कि मुझे, मैं इसे हर जगह आयात किया था के लिए काम किया लेकिन app.module.ts पर प्रदाताओं में जोड़ने के लिए भूल गया था app.module.ts

import { Geolocation } from '@ionic-native/geolocation'; 

providers: [ 
StatusBar, 
SplashScreen, 
{provide: ErrorHandler, useClass: IonicErrorHandler}, 
AuthService, 
EmailValidator, 
DataService, 
Geolocation 
] 

तब पेज पर मैं इस उदाहरण में एक टेस्ट होम के रूप में लेट और लम्बाई प्रदर्शित कर रहा था;

import { Geolocation } from '@ionic-native/geolocation'; 
lat: number; 
longt: number; 

this.geolocation.getCurrentPosition().then((resp) => { 
    this.lat = (resp.coords.latitude); 
    this.longt =(resp.coords.longitude); 
}).catch((error) => { 
    console.log('Error getting location', error); 
}); 

तो home.html पर {{अक्षां}} {{longt}}

मैं जानता हूँ कि यह केवल सरल था, लेकिन मैं सिर्फ यह मानचित्र में रखने के लिए पर जाने से पहले बाहर डेटा हो रही थी।

संबंधित मुद्दे