Ionic 3 - Open geolocation without navigation with Google Maps / Apple Maps app - ios

In my Ionic 3 app for Android and iOS, I need to open a specific geolocation with Google Maps (if installed) or Apple Maps. I discovered Launch Navigator which pretty much does the same.
Is there a way by which I can choose not to navigate to the specified location and only show a marker using Launch Navigator?
If not, are there any other alternatives to make this possible?

I had the same issue and this is what I came up with. There are three important steps
Check to see if the user is on iOS or Android
need to include Platform import { Platform } from 'ionic-angular';
If they are on iOS check for Google Maps
I'm using LaunchNavigator to check for the app
import { LaunchNavigator, LaunchNavigatorOptions } from '#ionic-native/launch-navigator';
Open the appropriate app with our GPS parameters
To open an external app we need the In App Browser
import { InAppBrowser } from '#ionic-native/in-app-browser';
then we have all we need to open Google Maps on iOS if it's available, with no navigation
if (this.platform.is('ios')) {
//try google maps first
this.launchNavigator.isAppAvailable(this.launchNavigator.APP.GOOGLE_MAPS).then(
response => {
if(response) {
window.open('comgooglemaps://?q=' + lat + ',' + lng + '(' + marker_name + ')', '_system');
}
else {
window.open('maps://?q=' + lat + ',' + lng, '_system');
}
},
failure => {
//check failed;
}
);
}
else if (this.platform.is('android')) {
window.open('geo://' + lat + ',' + lng + '?q=' + lat + ',' + lng + '(' + marker_name + ')', '_system');
}

Try this, it let the user to choose the app navigation (waze or map or...) to open, and add a marker on latitude and longitude given:
import { Platform } from '#ionic/angular';
...
constructor(
public platform: Platform
) {
}
public openMapsApp(lat: number, lng: number) {
const geocoords = lat + ',' + lng;
if (
this.platform.is('ios')
&& this.platform.is('iphone')
&& this.platform.is('ipad')
) {
window.open('maps://?q=' + geocoords, '_system');
return;
}
if (this.platform.is('desktop')) {
window.open('https://www.google.com/maps?q=' + geocoords);
return;
}
const label = encodeURI('7 East Street'); // encode the label!
window.open('geo:' + geocoords + '?q=' + geocoords + '(' + label + ')', '_system');
}

Related

How to query google maps from React Native iOS linking

I have an app with google maps link like this
const url = Platform.select({
ios: `https://www.google.com/maps/search/?api=1&query=${label}`,
android: `${scheme}${latLng}(${label})`
});
Linking.canOpenURL(url)
What I want to do is to query google maps using query=${lat},${lon} and using the name described as label above, because when I do the query, google maps open at the location but the pin displays the lat and long, and I want to display the label string
Please help!
I just figured it out. If you have google maps installed it will open the app with the desired location and pin correctly. If you don't have google maps installed it will open the browser with google maps and location! :)
const scheme = Platform.select({ ios: 'maps:0,0?q=', android: 'geo:0,0?q=' });
const latLng = `${your Lat},${your Long}`;
const label = this.state.clinic.name;
const url = Platform.select({
ios: `https://www.google.com/maps/search/?api=1&query=${label}&center=${lat},${long}`,
android: `${scheme}${latLng}(${label})`
});
Linking.canOpenURL(url)
.then((supported) => {
if (!supported) {
browser_url =
"https://www.google.de/maps/#" +
latitude +
"," +
longitude +
"?q=" +
label;
return Linking.openURL(browser_url);
} else {
return Linking.openURL(url);
}
})
.catch((err) => console.log('error', err));

Geolocation Using Ionic Cordova Returning Incorrect Lat/Long Values

I am facing issue using Geolocation pluggin with Ionic and Cordova framework.
Using Visual Studio Community 2015, with Cordova CLI version :4.3.0 and added the org.apache.cordova.geolocation pluggin to VSC-2015
My controller.js
.controller('MapCtrl', function ($scope) {
function onSuccess(position) {
console.log(position.timestamp);
console.log(position.coords.latitude + " " + position.coords.longitude);
}
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
navigator.geolocation.getCurrentPosition(onSuccess, onError);
})
Added the google maps into the index.html
<script src="https://maps.googleapis.com/maps/api/js?sensor=true&v=3.exp"></script>
Added a Map to my Map.html file
<div id="map" data-tap-disabled="true" map> </div>
The problem is I always get a fixed value of Lat/Long
ie Lat = 43.465187 and Long = -80.522372
This is not my correct Geolocation in terms of Lat/Long.I need my current Geolocation in terms of Lat/Long
Please help me identity the fault.
Also I am using Ripple -Nexus (Galaxy) on Browser.
Any help is appreciated...
Thanks,
Download the Latest version of GeoLocation pluggin from https://github.com/apache/cordova-plugin-geolocation
Then inject the $cordovaGeolocation into the controller.
Code is as below:
.controller('HomeCtrl', function($scope,$cordovaGeolocation) {
$scope.getLocation = function() {
var posOptions = {timeout: 10000, enableHighAccuracy: false};
$cordovaGeolocation
.getCurrentPosition(posOptions)
.then(function (position) {
//these are your your lat long values
var lat = position.coords.latitude
var long = position.coords.longitude
}, function(err) {
// error
});
}
})
Note: The device need to be connected to internet or wifi and also need to keep the GPS location ON in the device for getting the correct Lat/Long Values.
I am not sure why you get fixed lat/long values. However to get the device's position using Ionic, the following works for me:
ionic.Platform.ready($scope.getLocation);
$scope.getLocation = function () {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition($scope.showPosition, $scope.showError);
}
else {
console.log('Geolocation is not supported by this browser.');
}
}
$scope.showPosition = function (position) {
console.log(position.timestamp);
console.log(position.coords.latitude + ' ' + position.coords.longitude);
}
$scope.showError = function (error) {
switch (error.code) {
case error.PERMISSION_DENIED:
console.log('User denied the request for Geolocation.');
break;
case error.POSITION_UNAVAILABLE:
console.log('Location information is unavailable.');
break;
case error.TIMEOUT:
console.log('The request to get user location timed out.');
break;
case error.UNKNOWN_ERROR:
console.log('An unknown error occurred.');
break;
}
}
Note that the call to:
ionic.Platform.ready($scope.getLocation);
Is crucial, as you can only guarantee you'll get an accurate GPS fix once the device is ready/initialised.

How to get google map searched location lat & long in blackberry application?

I have used following code to call Google Maps which is installed in Blackberry device
public void invokeGMaps(GMLocation l) {
URLEncodedPostData uepd = new URLEncodedPostData(null, false);
uepd.append("action", "LOCN");
uepd.append("a",
"#latlon:" + l.getLatitude() + "," + l.getLongitude());
uepd.append("title", l.getName());
uepd.append("description", l.getDescription());
String[] args = { "http://gmm/x?" + uepd.toString() };
ApplicationDescriptor ad = CodeModuleManager.getApplicationDescriptors(mh)[0];
ApplicationDescriptor ad2 = new ApplicationDescriptor(ad, args);
try {
ApplicationManager.getApplicationManager().runApplication(ad2, true);
} catch (ApplicationManagerException e) {
System.out.println(e.getMessage());
Dialog.alert("error1 " + e.getMessage());
} catch (Exception e) {
Dialog.alert("error2 " + e.getMessage());
}
}
this is working fine. I have passed current postion to it.
Suppose user will search any particular location on google maps after going on google maps. so while returning back to application i want searched location latitude & longitude from google maps.
So please give me idea how i will get it in my application from google maps application?
Please help me, or any help regarding search location on blackberry how to done it?
Thanks for reading my question patiently.

Geo Location not works in BlackBerry

I have developed an application using phonegap to retrieve Geo Location.
function getLoc() {
navigator.geolocation.getCurrentPosition(onSuccess, onError, { enableHighAccuracy: true });
}
// onSuccess Geolocation
function onSuccess(position) {
var locInfo = new Object();
locInfo.Latitude = position.coords.latitude;
locInfo.Longitude = position.coords.longitude;
locInfo.Altitude = position.coords.altitude;
locInfo.Accuracy = position.coords.accuracy;
locInfo.AltitudeAccuracy = position.coords.altitudeAccuracy;
locInfo.Heading = position.coords.heading;
locInfo.Speed = position.coords.speed;
alert(locInfo.Latitude + " " + locInfo.Longitude);
}
// onError Callback receives a PositionError object
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
above code is working fine in Android, iPhone and BlackBerry Simulator, but not in BlackBerry device. I'm using BlackBerry Torch for testing.
what could be the issue. pls reply.
Thanks :)
Try to set timeout for getCurrentPosition.

Blackberry: Command line build and application auto-start

I have an application which is built from command line (ANT) using J2ME Polish. As such, this application is defined through a build.xml, not from Blackberry JDE project files.
What I need to do is have this application auto-start. This is easy enough to do once the application has been run for the first time (example). However, this does require the application to be manually run by the user (which I want to avoid).
The JDE provides options which you can check to enable auto-start, and from ANT:
<cldc runonstartup=="true"...
Will do the trick. The question is, how do I integrate this into a Polish buiild (i.e. into a Polish build.xml which is also building for other platforms)?
Anyone know what the auto-start option in the JDE actually does / what it changes?
So, the way to do this is, unfortunately, to change the J2ME-Polish source! As outlined in this bug report the J2ME Polish build framework (at version 2.1.4) doesn't pass on the RIM-MIDlet-Flags-x JAD attribute to RAPC.
The changes are relatively simple - merely passing on the RIM-MIDlet-Flags-1 value if defined in the JAD, otherwise setting it to zero (as the original 2.1.4 source does).
The diff (from 2.1.4) source:
Index: /enough-polish-build/source/extensions/de/enough/polish/blackberry/JarToCodFinalizer.java
===================================================================
--- /enough-polish-build/source/extensions/de/enough/polish/blackberry/JarToCodFinalizer.java (revision 315)
+++ /enough-polish-build/source/extensions/de/enough/polish/blackberry/JarToCodFinalizer.java (revision 316)
## -36,6 +36,7 ##
import java.util.Calendar;
import java.util.Locale;
import java.util.Map;
+import java.util.List;
import java.util.Properties;
import org.apache.tools.ant.BuildException;
## -185,6 +186,13 ##
}
}
File iconFile = null;
+ Map jadProperties;
+ try {
+ jadProperties = FileUtil.readPropertiesFile( jadFile, ':' );
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new BuildException("Unable to read JAD file " + e.toString() );
+ }
if (mainClassName != null) {
try {
/*
## -230,12 +238,26 ##
"MicroEdition-Configuration: CLDC-1.1",
//"MIDlet-1: Demo," + iconUrl + ",",
"MIDlet-1: " + env.getVariable("MIDlet-Name") + "," + iconUrl + ",",
- //"MIDlet-Icon: " + iconUrl,
- "RIM-MIDlet-Flags-1: 0"
+ //"MIDlet-Icon: " + iconUrl
};
+ /* Ensure that if RIM-MIDlet-Flags is defined in the JAD, it is
+ * passed on to RAPC to create the COD file.
+ * See https://developer.berlios.de/bugs/?func=detailbug&group_id=1246&bug_id=16901
+ * for details.
+ */
+ ArrayList newEntriesList = new ArrayList(Arrays.asList(newEntries));
+ final String flagsKey = "RIM-MIDlet-Flags-1";
+ String flagString = (String)jadProperties.get(flagsKey);
+ if (flagString == null) {
+ flagString = "0";
+ }
+ flagString = flagString.trim();
+ System.out.println("JarToCodFinalizer setting " + flagsKey + ": " + flagString);
+ newEntriesList.add(flagsKey+ ": " + flagString);
+
File rapcFile = new File( jadFile.getParent(), codName + ".rapc");
- FileUtil.writeTextFile( rapcFile, newEntries );
+ FileUtil.writeTextFile( rapcFile, newEntriesList );
} catch ( IOException e ) {
// this shouldn't happen
e.printStackTrace();
## -367,7 +389,6 ##
// now rewrite JAD file so that it is ready for OTA download:
// (first backup JAD file:)
//FileUtil.copy(jadFile, new File(jadFile.getParent(), jadFile.getName() + ".bak") );
- Map jadProperties = FileUtil.readPropertiesFile( jadFile, ':' );
Object[] keys = jadProperties.keySet().toArray();
for (int i = 0; i < keys.length; i++) {
String key = (String) keys[i];
Another polish user :)
Take a look at BB forums the 2nd post. Then using what we know about polish and jad attributes
Add this to your jad section of your build.xml
<jad>
<attribute name="RIM-MIDlet-Flags"
value="1"
if="polish.vendor == BlackBerry" />
</jad>
I haven't tested this but the logic seems to be valid :) Let me know if it works or not.

Resources