I'm creating an ios app with phonegap 3.2 I need users current location to search nearby users. When i tried to get current location of device with code
function onSuccess(position) {
device_lat = position.coords.latitude;
device_long = position.coords.longitude;
}
// onError Callback receives a PositionError object
function onError(error) {
alert("Share Your Location First.");
}
function onDeviceReady()
{
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
A confirm box appearing with following text.
"/Users/../Library/Application Support/iPhone Simulators/6.1/Applications/[App Code here]/demo.app/www/index.html" Would Like To Use Your Current Location.
Is it possible to costomise this text as its say Like
"MyApp Would Like To Use Your Current Location" ?
Also for android and other devices.
I'm posting a new answer since the last one was incomplete. In order to get the geolocation prompt title to show your app name and not the full path to the file you'll need to do two things:
Install the Cordova / PhoneGap geoLocation pluin (cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git)
Run the getCurrentPosition after deviceready has been fired.
$(document).ready(function(){
$(function(){
document.addEventListener("deviceready", onDeviceReady, false);
})
function onDeviceReady() {
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
});
I removed cordova geolocation plugin and everything working well. I'm using phonegap 3. navigator.geolocation.getCurrentPosition(onSuccess, onError); is also a html5 function so no need to other changes. Now it giving confirm box with message.
"MyApp Would Like To Use Your Current Location"
MyApp is the title of index page.
Related
I have a problem using Geolocation on Android device.
I create an Ionic 3 application.
I use Geolocation ( [https://ionicframework.com/docs/native/geolocation/ 13]).
I use the sample code provided there.
The problem is that, the code works in Browser but whenever I upload it on an Android device, it does not work.
When I start the app on device the alert for location permission is prompted.
I press Allow.
Then in the android tray an icon appears that says “Searching for GPS”.
After timeout expires I got the error for timeout and no location.
The strange think is this:
If I close my app, then open google maps ( or other app using gps position ) and reopen my app works as it should.
I don’t know what to do.
The permissions are fine :
and everything was installed properly.
Can anyone help please?
i got it actually i have to pass apikey with that like
<script src="http://maps.googleapis.com/maps/api/js?key=YOUR_KEY"></script>
in the index page
without this key it sometime works but not sure everytime.
Note : this key is only generated when you have a valid gmail a/c (by providing DOB/CreditCard nos) although its free .
try this, it should work
ionic cordova run android --prod
--prod makes production build apk
import { LocationAccuracy } from '#ionic-native/location-accuracy';
declare var navigator
Above
#Component
watchPosition() {
this.locationAccuracy.request(this.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY).then(
() => {
var options = {
timeout: 500,
maximumAge: Infinity
};
this.watch = navigator.geolocation.watchPosition((data) => {
let latlng: LatLng = new LatLng(data.coords.latitude, data.coords.longitude);
}, (error) => {
console.log("error watch", error)
}, options);
}
}, error => {
alert('Error requesting location permissions' + JSON.stringify(error))
});
}
}
I am trying to get a compass function working on my app with no success. Judging by the errors I am inclined to think that the plugin is not being added or the device is not ready. But as far as I can tell I have done both things. I am using phonegap build, so the only code I use to include it is:
<gap:plugin name="org.apache.cordova.device-orientation" version="0.3.9" />
Which as far as I know is all that is required. When I click on the plugins tab in the phonegap build page for my app it shows up as being there.
watchDirection = null;
//Phonegap is ready
var whenDeviceReady = function(){
console.log("deviceready");
console.log(navigator.compass);
var findMyDirection = function(){
console.log("find my heading fired");
watchDirection = navigator.compass.watchHeading(
//onSuccess
function(heading){
console.log(heading);
var magnetDirection = heading.magneticHeading;
$("#movingCompass").css("transform", "rotate(" + magnetDirection + "deg)");
},
//onError
function(error){
console.log('code: ' + error.code +' message: ' + error.message);
},
//Update Frequency
{ frequency: 1000});
}
findMyDirection();
}
//Wait for phonegap to load
document.addEventListener("deviceready", whenDeviceReady, false);
The above code works as expected with the exception of the compass object. The console.log(navigator.compass); returns as undefined. And there is an error on the line which includes watchDirection = navigator.compass.watchHeading( saying Uncaught TypeError: Cannot read property 'watchHeading' of undefined.
It gets listed in the phonegap build list of installed plugins, and I already have the geolocation working with the same code format I have posted above.
#Marty.H, I have working demos here: http://codesnippets.altervista.org/examples/phonegap/demos/PUBLIC.Apps.html Go to the lower half of the page and try pre-built app, Phonegap-Compass-Test. If it works, the top half of the page has the links to github where you can get the source code. --Jesse
Good day! I am developing a simple mobile app using jQuery Mobile with InAppBrowser plugin on IntelXDK. The purpose of the InAppBrowser is to let users view external web pages within the app. On IntelXDK emulator, the browser closes when I click on "Return to App" button and then it returns to the app. However, I encountered a problem on an Android build when I clicked on the "Done" button I received the message:
Webpage not available
The webpage at file:///android_asset/www/[object%20Event] might be temporarily down...
I have used the following so users can click and view external web pages:
Opening links in external device browser with Cordova/jQuery-mobile
I have modified the above to be used on my app:
$(document).on('click', '.link', function (e) {
var elem = $(this);
var url = elem.attr('href');
if (url.indexOf('http://') !== -1) {
e.preventDefault();
document.addEventListener("deviceready", onDeviceReady, false);
onDeviceReady(url);
//return false;
}
});
function onDeviceReady(url) {
var ref = window.open(url, '_blank', 'location=yes');
}
Thank you for your time and help. I really appreciate it.
The reason why it was displaying an error message because the test file was calling another onDeviceReady function. Problem solved!
I AM creating a phonegap android app. I am creating this app using help of this tutorial. When i am istalling this app on device its onDeviceReady function is not working. It is only showing coneecting to device. My onDeviceReady function is below:-
onDeviceReady: function() {
app.receivedEvent('deviceready');
alert('device ready');
try {
var pushNotification = window.plugins.pushNotification;
pushNotification.register(app.successHandler, app.errorHandler,{"senderID":"41327727848","ecb":"app.onNotificationGCM"});
} catch (ex) {
alert('error: ' + ex);
}
},
It does not alert anything. I can't find the error.
Here are the suggestions you can try:
make sure you have added cordova.js into your html file.
deviceready function should be called after cordova.js is loaded.
the link you've provided is using old version version of plugin.(link-old plugin).I advice you to follow the new one which is this
Any suggestions on why I'm not getting events?
I'm opening the browser after deviceready:
document.addEventListener('deviceready', app.login, false);
I register the event listener, the login function below is called as expected, the foobar page opens, but I never get the "loadstart" (or any other) callbacks that I register for:
login: function () {
console.log("login");
var authorize_url = "foobar";
var appInBrowser = window.open(authorize_url, '_blank', 'location=yes');
appInBrowser.addEventListener('loadstart', function(event) { console.log('loadstart'); });
}
As far as I can tell I'm following the Cordova docs example. Thanks.
Solution: Don't forget to manually install the plugin. Without the plug-in the browser will still show up, but events won't fire:
Use the command line interface:
cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git