sebastianbaar / cordova-plugin-nativegeocoder Goto Github PK
View Code? Open in Web Editor NEWCordova plugin for native forward and reverse geocoding
License: MIT License
Cordova plugin for native forward and reverse geocoding
License: MIT License
Since a hardcoded string is set in the plugin.xml file for NSLocationWhenInUseUsageDescription, the value that comes from other plugins that use variables instead is overwritten with the string "Using geocoder service" which cannot be changed.
The right way to implement this would be something like:
<preference name="GEOLOCATION_USAGE_DESCRIPTION" default=" " />
<config-file target="*-Info.plist" parent="NSLocationWhenInUseUsageDescription">
<string>$GEOLOCATION_USAGE_DESCRIPTION</string>
</config-file>
The forward geocoding function returns an array of latitude, longitude values. This is not enough for my application, because the user reasonably needs the names of the locations returned to choose from. The formatted_address value of the geocoding service is good to have because the user may not type in a full address (ex. 'Philadelph', so the app cannot rely on the user input later on to identify/label this location. The type of the location returned is also interesting and would be nice to have it.
In the google geocoding service, the values requested here are:
types[]: string,
formatted_address: string,
See also:
https://developers.google.com/maps/documentation/javascript/geocoding#GeocodingAddressTypes
https://developers.google.com/maps/documentation/geocoding/intro
Thank you for the great package!
I have tried this plugin in my demo app. Its giving me following error on build.
/node_modules/ionic-native/dist/es5/index"' has no exported member 'NativeGeocoder', 'NativeGeocoderReverseResult', 'NativeGeocoderForwardResult'.
ionic-native version: 2.2.11
The plugin is working very well on Android, but I am having a weird problem on IOS and it is a runtime problem and not a build problem, I am getting an error on Xcode console saying:
CLGeocoder:geocodeAddressString Error
And it is not working
Plugin Version
v3.1.0
Smartphone:
Tested on iPhone 6
Hi,
I'd like to know what is the main difference between this plugin and the geocoder of cordova-plugin-googlemaps here
Thanks
Best Regards
Hello
i have download the new iOS 13 to build the a new Version from the App. And i see that the thoroughfare not shown anymore.
Can you check this?
Thx
Hello,
It is not possible to install the plugin if you use cordova 8 (on a Mac at least). This is because of the
<dependency id="cordova-plugin-add-swift-support" version="1.7.0"/>
in the file plugin.xml, row 45. The add-swift-support plugin has a bug in version 1.7.0 which is resolved in 1.7.1. Is it possible to change the dependency?
The changes can be checked here: https://github.com/akofman/cordova-plugin-add-swift-support/releases/tag/1.7.1
I have noticed that the address return value is in the language of phone setting.
Is there any way I can set the language option only in English no matter what the phone setting is?
When I run the command ionic cordova plugin add cordova-plugin-nativegeocoder
, I get the following error:
Failed to fetch plugin cordova-plugin-nativegeocoder via registry.
Probably this is either a connection problem, or plugin spec is incorrect.
Check your connection and plugin name/version/URL.
Error: npm: Command failed with exit code 1 Error output:
npm ERR! Cannot read property 'match' of undefined
ionic-angular: v3.6.1
I'm getting an TypeError: Object(...) is not a function
error when trying to use Native Geocoder.
Code is below:
import { NativeGeocoder, NativeGeocoderOptions, NativeGeocoderReverseResult,
NativeGeocoderForwardResult } from '@ionic-native/native-geocoder'; constructor(private Platform: Platform, public loadingCtrl: LoadingController, private router: Router, public natGeo: NativeGeocoder) {}
... let options: NativeGeocoderOptions = { useLocale: true, maxResults: 5 };
this.natGeo.forwardGeocode('Berlin', options) .then((coordinates: NativeGeocoderForwardResult[]) => console.log('The coordinates are latitude=' + coordinates[0].latitude + ' and longitude=' + coordinates[0].longitude)) .catch((error: any) => console.log(error)); ...
How can I get this to work please?
Hello,
I tried to use plugin ionic 3
this.nativeGeocoder.reverseGeocode ==== i got this error ("Cannot get an address.")
this.nativeGeocoder.forwardGeocode ==== i got this error Cannot find a location.
and that my page
`import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, Platform } from 'ionic-angular';
import { NativeGeocoder, NativeGeocoderReverseResult, NativeGeocoderForwardResult, NativeGeocoderOptions } from '@ionic-native/native-geocoder';
@IonicPage()
@Component({
selector: 'page-test',
templateUrl: 'test.html',
})
export class TestPage {
constructor(public navCtrl: NavController,private platform:Platform , public navParams: NavParams,private nativeGeocoder: NativeGeocoder) {
}
ionViewDidLoad() {
console.log('ionViewDidLoad TestPage');
if (this.platform.ready())
{
this.loadAddress();
}
}
loadAddress()
{
let options: NativeGeocoderOptions = {
useLocale: true,
maxResults: 5
};
this.nativeGeocoder.reverseGeocode(52.5072095, 13.1452818, options)
.then((result: NativeGeocoderReverseResult[]) => console.log(JSON.stringify(result[0])))
.catch((error: any) => console.log(error));
this.nativeGeocoder.forwardGeocode('Berlin', options)
.then((coordinates: NativeGeocoderForwardResult[]) => console.log('The coordinates are latitude=' + coordinates[0].latitude + ' and longitude=' + coordinates[0].longitude))
.catch((error: any) => console.log(error));
}
}
`
thanks
I am developing a hybrid mobile app in ionic2. I want to get lat-long base on the address.
Following is my code:
this.nativeGeocoder.forwardGeocode('20 Greenway Rockville Centre NY 11570') .then((coordinates: NativeGeocoderForwardResult) => console.log('The coordinates are latitude=' + coordinates.latitude + ' and longitude=' + coordinates.longitude)) .catch((error: any) => console.log(error));
On ios, i am getting latitude = 40.661109 and longitude=-73.626429 which is wrong. The correct lat-long is latitude = 40.660858 and longitude=73.626354.
What could be the issue?
Hi
I really loved this plugin. Thanks for great job.
It would be very helpful if you let the use select locale. I mean in addition to useLocale add an option parameter which is a string and accepts locales like "en-US" or "fa-IR", ...
Thanks
Type 'NativeGeocorderOriginal' is not assignable to type 'Provider'
Type 'NativeGeocoderOriginal' is missing the following properties from type ''FactoryProvider: provide, useFactory
This is my code
`import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { NativeGeocoder } from '@ionic-native/native-geocoder';
@NgModule({
declarations: [
MyApp,
HomePage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
providers: [
NativeGeocoder,
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}`
I would really appreciated, if you guys could help me.
When execute the following code, fall into failure function, and alert: "CLGecoder:reverseGeocodeLocation Error".
nativegeocoder.reverseGeocode(success, failure, 30.649908, 104.014556);
function success(result) {
alert("The address is: \n\n" + JSON.stringify(result));
}
function failure(err) {
alert(JSON.stringify(err));
}
How to fix the problem? Help me. Please.
Hi guys!
I get an error when trying to geocoding the coordinates on iOS1. Before updating the OS, everything was ok. Android also works without problems. Perhaps you can tell the reason?
this.nativeGeocoder.reverseGeocode(coordinates.lat, coordinates.long, options) .then((result: NativeGeocoderReverseResult[]) => { console.log(result[0]); }) .catch((error: any) => { console.log('reverseGeocodeErr', error); });
Hey, I'am trying to build to iOS but Im getting these errors.
Using Swift 1.7.1.
`Users/Me/app-ios/platforms/ios/appName/Plugins/cordova-plugin-nativegeocoder/NativeGeocoder.swift:5:48: warning: extraneous '_' in parameter: 'command' has no keyword argument name
@objc(reverseGeocode:) func reverseGeocode(_ command: CDVInvokedUrlCommand) {
^~
/Users/Me/app-ios/platforms/ios/appName/Plugins/cordova-plugin-nativegeocoder/NativeGeocoder.swift:80:45: warning: extraneous '_' in parameter: 'command' has no keyword argument name
@objc(forwardGeocode:)func forwardGeocode(_ command: CDVInvokedUrlCommand) {
^~
/Users/Me/app-ios/platforms/ios/appName/Plugins/cordova-plugin-nativegeocoder/NativeGeocoder.swift:24:52: error: value of type 'CLPlacemark' has no member 'isoCountryCode'
resultObj["countryCode"] = placemark.isoCountryCode ?? ""
^~~~~~~~~ ~~~~~~~~~~~~~~
/Users/Me/app-ios/platforms/ios/appName/Plugins/cordova-plugin-nativegeocoder/NativeGeocoder.swift:34:55: error: incorrect argument label in call (have 'status:messageAs:', expected 'status:messageAsDictionary:')
pluginResult = CDVPluginResult(
^
/Users/Me/app-ios/platforms/ios/appName/Plugins/cordova-plugin-nativegeocoder/NativeGeocoder.swift:42:55: error: incorrect argument label in call (have 'status:messageAs:', expected 'status:messageAsString:')
pluginResult = CDVPluginResult(
^
/Users/Me/app-ios/platforms/ios/appName/Plugins/cordova-plugin-nativegeocoder/NativeGeocoder.swift:51:51: error: incorrect argument label in call (have 'status:messageAs:', expected 'status:messageAsString:')
pluginResult = CDVPluginResult(
^
/Users/Me/app-ios/platforms/ios/appName/Plugins/cordova-plugin-nativegeocoder/NativeGeocoder.swift:58:37: error: value of type 'CDVCommandDelegate' has no member 'send'
self.commandDelegate!.send(
~~~~~~~~~~~~~~~~~~~~^ ~~~~
/Users/Me/app-ios/platforms/ios/appName/Plugins/cordova-plugin-nativegeocoder/NativeGeocoder.swift:67:43: error: incorrect argument label in call (have 'status:messageAs:', expected 'status:messageAsString:')
pluginResult = CDVPluginResult(
^
/Users/Me/app-ios/platforms/ios/appName/Plugins/cordova-plugin-nativegeocoder/NativeGeocoder.swift:72:33: error: value of type 'CDVCommandDelegate' has no member 'send'
self.commandDelegate!.send(
~~~~~~~~~~~~~~~~~~~~^ ~~~~
/Users/Me/app-ios/platforms/ios/appName/Plugins/cordova-plugin-nativegeocoder/NativeGeocoder.swift:101:55: error: incorrect argument label in call (have 'status:messageAs:', expected 'status:messageAsDictionary:')
pluginResult = CDVPluginResult(
^
/Users/Me/app-ios/platforms/ios/appName/Plugins/cordova-plugin-nativegeocoder/NativeGeocoder.swift:108:55: error: incorrect argument label in call (have 'status:messageAs:', expected 'status:messageAsString:')
pluginResult = CDVPluginResult(
^
/Users/Me/app-ios/platforms/ios/appName/Plugins/cordova-plugin-nativegeocoder/NativeGeocoder.swift:117:51: error: incorrect argument label in call (have 'status:messageAs:', expected 'status:messageAsString:')
pluginResult = CDVPluginResult(
^
/Users/Me/app-ios/platforms/ios/appName/Plugins/cordova-plugin-nativegeocoder/NativeGeocoder.swift:126:47: error: incorrect argument label in call (have 'status:messageAs:', expected 'status:messageAsString:')
pluginResult = CDVPluginResult(
^
/Users/Me/app-ios/platforms/ios/appName/Plugins/cordova-plugin-nativegeocoder/NativeGeocoder.swift:133:33: error: value of type 'CDVCommandDelegate' has no member 'send'
self.commandDelegate!.send(
~~~~~~~~~~~~~~~~~~~~^ ~~~~
/Users/Me/app-ios/platforms/ios/appName/Plugins/cordova-plugin-nativegeocoder/NativeGeocoder.swift:143:39: error: incorrect argument label in call (have 'status:messageAs:', expected 'status:messageAsString:')
pluginResult = CDVPluginResult(
^
/Users/Me/app-ios/platforms/ios/appName/Plugins/cordova-plugin-nativegeocoder/NativeGeocoder.swift:148:29: error: value of type 'CDVCommandDelegate' has no member 'send'
self.commandDelegate!.send(
~~~~~~~~~~~~~~~~~~~~^ ~~~~
** BUILD FAILED **
The following build commands failed:
CompileSwift normal x86_64 /Users/Me/app-ios/platforms/ios/appName/Plugins/cordova-plugin-nativegeocoder/NativeGeocoder.swift
CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
(2 failures)
Error: Error code 65 for command: xcodebuild with args: -xcconfig,/Users/Me/app-ios/platforms/ios/cordova/build-debug.xcconfig,-workspace,appName.xcworkspace,-scheme,appName,-configuration,Debug,-sdk,iphonesimulator,-destination,platform=iOS Simulator,name=iPhone 6s Plus,build,CONFIGURATION_BUILD_DIR=/Users/Me/app-ios/platforms/ios/build/emulator,SHARED_PRECOMPS_DIR=/Users/Me/app-ios/platforms/ios/build/sharedpch
[ERROR] An error occurred while running cordova build ios (exit code 1).`
Im guessing it has something to do with swift, however I do not know how to fix this so I might aswell just post it here...
I just wanted to know, is there any hits limit? Like if we use google api to get location details, we used to have some hits limit if the account is not paid. After exceeding the hits quota we cant call the goole api to get address.
I tried to add nativegeocoder in my Ionic App and executed the reverseGeocode function. In the browser, it showed that cordova is not available. Then I run my app in android device, it showed that Geocoder is not present on this device/emulator. How can I fix this problem?
Is it possible to return the list of locations instead of just one?
e.g. I reckon typing in something ambiguous like 'depot' would yield many possible results? since Android geocoder api states that they return a list.
thanks!
I've been building an Ionic/Cordova app with a lot of success but now that I've added this plugin everytime I run "Cordova run ios" it now takes 5 minutes instead of 15 seconds to build the app.
It seems to hang at the line "NativeGeocoder.o".
What is it doing that whole time? Feels like it's downloading something heavy... How do I resolve this as it's now becoming a massive time constraint while working on other features. Plus to make matters worse the device times out and locks so half the time I have to re-run the 5 minute build simply based on a permission issue.
Sorry for such a "petty" issue but I've googled to no avail. No other package has caused this issue.
Is your feature request related to a problem? Please describe.
A simple but kind of required feature is to return, along with current Address class values, the value of addressLine which in web API is similar to formatted_address, as creating the address string is sometimes both overhead and improper.
Describe the solution you'd like
Just start returning the addressLine in the current response.
Describe alternatives you've considered
We now have to construct own address which is not as good and helpful for users. The "unnamed road" and other such keywords irritates users.
I am getting grpc failed error while using **forward geocoder** most of the time.
Kindly help to resolve this.
Could you please add a license file to this repo? Currently it's unclear what are the terms and conditions of using NativeGeocoder plugin code.
Many thanks in advance!
I use this code but it shows above error
this.nativeGeocoder.reverseGeocode(this.letitude, this.longitude, options)
.then((result: NativeGeocoderReverseResult[]) =>{
console.log(result);
console.log(JSON.stringify(result[0]));
Describe the bug
When calling reverseGeocode with null options, it prints this error stacktrace:
W/System.err: org.json.JSONException: Value null at 2 of type org.json.JSONObject$1 cannot be converted to JSONObject
at org.json.JSON.typeMismatch(JSON.java:100)
at org.json.JSONArray.getJSONObject(JSONArray.java:525)
at cordova.plugin.nativegeocoder.NativeGeocoder.execute(NativeGeocoder.java:43)
W/System.err: at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:98)
at org.apache.cordova.PluginManager.exec(PluginManager.java:132)
at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:59)
at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:325)
at android.os.Looper.loop(Looper.java:142)
at android.os.HandlerThread.run(HandlerThread.java:65)
But it otherwise works fine. It doesn't seem like that should be printed. It's ok to pass null options.
To Reproduce
Call reverseGeocode with null options
Expected behavior
No error logging
Plugin Version
latest
Smartphone (please complete the following information):
Any
Additional context
None
I am getting "Geocoder:getFromLocationName Error: grpc failed" while using reverseGeocode.
It works after i switch on flight mode and wait for 10 seconds before switching it off again.
Any idea? Is there any fix or workaround for this?
The response to the reverseGeocode function is incomplete and does not return the fields thoroughfare and subThoroughfare
This is my code:
this.nativeGeocoder.reverseGeocode(position.coords.latitude, position.coords.longitude, { useLocale: true, maxResults: 1 }) .then((result: NativeGeocoderReverseResult[]) => { console.log(JSON.stringify(result)); }) .catch((error: any) => console.log(error));
the previous code only returns:
[{"countryCode":"ES","countryName":"España","postalCode":"08013","locality":"Barcelona","subLocality":"Barcelona"}]
Hi , i was working in geocoding and getting lat long for an address or zipcode which is being entered by the user, when i was testing with 10004 zipcode, which is near newyork, we are getting different lat long for different devices example : samsung galaxy s7 returns lat : 40.705478 long : -74.015044 where as in lenovo k4 note returns lat : 48.586179 long : 4.107207 . I don't know why it is returning different lat long for same zipcode . Can you please help me on this.
Is there a way on this plugin to work offline(without internet but enabled location) ?
During my approval of an App for the AppStore I hit a bug, that puzzles me a lot.
The Apple headquarter is located at: Apple Infinite Loop, 1 Infinite Loop, Cupertino, Californien, USA
On Android I get the location 37.3316756, -122.030189 but on iPhone I get the error message: "Cannot get a location"
If I search for: "Apple, Infinite Loop, Cupertino, Californien, USA" or "Apple, 1 Infinite Loop, Cupertino, Californien, USA" it works fine on both platforms.
I am using Google Places to find the address, when the user enters the address.
Is there any way i can pass array of locations to get lat,lng in bulk?
Describe the bug
The cordova-plugin-add-swift-support
1.7.2 does not support cordova 9. Instaling your plugin in a cordova 9 project theirfore result in this error:
Using "requireCordovaModule" to load non-cordova module "glob" is not supported. Instead, add this module to your dependencies and use regular "require" to load it.
To Reproduce
Steps to reproduce the behavior:
Using "requireCordovaModule" to load non-cordova module "glob" is not supported. Instead, add this module to your dependencies and use regular "require" to load it.
Expected behavior
Should work also for cordova 9
Plugin Version
v3.2.1
Smartphone (please complete the following information):
I started using cordova geocoder in my project. In my first attempts to use it, it wasn't working, falling into the catch exception. And in a day, out of nothing, it started to work, returning me the adress. And, now, a few days later, it stopped working again. Is there any problem with its service? Because I'm sure I haven't changed my code so it stop working.
While searching for coordinates, i.e. forwardGeocoding, the plugin is returning "Cannot find a location."
This is the method in my provider -
//This calls the Native geocoder and returns the geocoordinates. getGeoCode(address: string): Promise<any> { console.log('The address key is - ' + address); return new Promise((resolve, reject) => { this.nativeGeocoder.forwardGeocode(address) .then((nativegeocoordinates: NativeGeocoderForwardResult) => { console.log('The coordinates are - ' + JSON.stringify(nativegeocoordinates)); let addressCoordinates: DeliveryAddressCoordinates = nativegeocoordinates; resolve(addressCoordinates); }) .catch((error: any) => { console.log(JSON.stringify(error)); reject(error); }); }) }
The method accepts an address string as input. So I get the address from google places API, and pass the description here.
Now, for certain addresses, it just doesn't seem to find the coordinates, and returns a "Cannot find a location" message. For e.g. "Bhadra Brookefields Apartment B Block, Kundanahalli Lake Road, Kundalahalli, Brookefield, Bengaluru, Karnataka, India" is a valid address and returns the coordinates, while "Times Square 42 Street Station, New York, NY, USA" does not find a match and returns a message saying - "Cannot find a location".
The "Cannot find a location" seems to be originating from the code here on line #182, where it is referencing the Android class.
Is this a known issue? Or is there something that I am doing wrong?
May you please explain what Android (works only on native devices) mean? Specifically native devices?
Hello, i install this package, when i am going to use it, it gives me "Error: [$injector:unpr] Unknown provider: NativeGeocoderProvider " error.
Below is my code .
function Search1Controller($log, header, DialogService, $auth, $localStorage, $state, $rootScope, $scope, API, mapbox, geo, $document, $interval, $timeout, broadcast, toast, $cordovaGeolocation, NativeGeocoder) {
and..
.reverseGeocode(success, failure, 52.5072095, 13.1452818);
function success(result) {
alert("The address is: \n\n" + JSON.stringify(result));
}
function failure(err) {
alert(JSON.stringify(err));
}
Describe the bug
While running an reverse/forward geocoding the main thread is blocked by up to 4 seconds
To Reproduce
Steps to reproduce the behavior:
reverseGeocode
on a low internet connection.reverseGeocode
is runningTHREAD WARNING: exec() call to NativeGeocoder.reverseGeocode blocked the main thread for 3639ms. Plugin should use CordovaInterface.getThreadPool()
Expected behavior
The reverse/forward geocoding should run in a background thread without blocking the ui.
Plugin Version
v3.2.2
Smartphone (please complete the following information):
Additional context
There are some suggestion how to resolve this issue:
IntentService
described in https://developer.android.com/training/location/display-address#javaXCode 8 can no longer compile apps that use an older version of Swift. The automatic converting feature of XCode seem to work fine, the build did not throw any errors afterwards. But I haven't tested the plugin yet.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.