Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigating based on the address info as street, city, region and country #183

Closed
wants to merge 11 commits into from
Closed
6 changes: 4 additions & 2 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ export const isIOS = Platform.OS === 'ios';

export function generatePrefixes(options) {
return {
'apple-maps': isIOS ? 'maps://' : 'applemaps://',
'apple-maps': isIOS ? 'http://maps.apple.com' : 'applemaps://',
'google-maps': prefixForGoogleMaps(options.alwaysIncludeGoogle),
citymapper: 'citymapper://',
// uber: isIOS ? 'https://m.uber.com/ul/' : 'uber://',
uber: 'uber://',
lyft: 'lyft://',
transit: 'transit://',
Expand All @@ -33,7 +34,8 @@ export function generatePrefixes(options) {
export function prefixForGoogleMaps(alwaysIncludeGoogle) {
return isIOS && !alwaysIncludeGoogle
? 'comgooglemaps://'
: 'https://www.google.com/maps/';
// : 'https://www.google.com/maps/';
: 'https://maps.google.com/';
}

export function generateTitles(titles) {
Expand Down
77 changes: 41 additions & 36 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export async function showLocation(options) {
checkOptions(options, prefixes);

let useSourceDestiny = false;
let useDstAddr = false;
let sourceLat;
let sourceLng;
let sourceLatLng;
Expand All @@ -44,25 +45,31 @@ export async function showLocation(options) {
sourceLatLng = `${sourceLat},${sourceLng}`;
}

const lat = parseFloat(options.latitude);
const lng = parseFloat(options.longitude);
const latlng = `${lat},${lng}`;
const title = options.title && options.title.length ? options.title : null;
const encodedTitle = encodeURIComponent(title);
if (('dstaddr' in options)) {
useDstAddr = true
}

let dstaddr = options.dstaddr && options.dstaddr.length ? options.dstaddr : null
let encodedDstaddr = dstaddr ? encodeURIComponent(dstaddr) : null
let lat = parseFloat(options.latitude);
let lng = parseFloat(options.longitude);
let latlng = `${lat},${lng}`;
let title = options.title && options.title.length ? options.title : null;
let encodedTitle = encodeURIComponent(title);
let app = options.app && options.app.length ? options.app : null;
const dialogTitle =
let dialogTitle =
options.dialogTitle && options.dialogTitle.length
? options.dialogTitle
: 'Open in Maps';
const dialogMessage =
let dialogMessage =
options.dialogMessage && options.dialogMessage.length
? options.dialogMessage
: 'What app would you like to use?';
const cancelText =
let cancelText =
options.cancelText && options.cancelText.length
? options.cancelText
: 'Cancel';
const appsWhiteList =
let appsWhiteList =
options.appsWhiteList && options.appsWhiteList.length
? options.appsWhiteList
: null;
Expand All @@ -83,26 +90,23 @@ export async function showLocation(options) {
switch (app) {
case 'apple-maps':
url = prefixes['apple-maps'];
url = useSourceDestiny
? `${url}?saddr=${sourceLatLng}&daddr=${latlng}`
: `${url}?ll=${latlng}`;
url += `&q=${title ? encodedTitle : 'Location'}`;
url += `?q=${title ? encodedTitle : 'Location'}`;
url += useDstAddr ? `&daddr=${encodedDstaddr}` : `&daddr=${latlng}`
url += useSourceDestiny
? `&saddr=${sourceLatLng}` : '';
break;
case 'google-maps':
// Always using universal URL instead of URI scheme since the latter doesn't support all parameters (#155)
url = 'https://www.google.com/maps/dir/?api=1';
if (useSourceDestiny) {
url += `&origin=${sourceLatLng}`;
}
if (!options.googleForceLatLon && title) {
url += `&destination=${encodedTitle}`;
} else {
url += `&destination=${latlng}`;
}
let useTitleForQuery = !options.googleForceLatLon && title
let googlePlaceId = options.googlePlaceId ? options.googlePlaceId : null

url += options.googlePlaceId
? `&destination_place_id=${options.googlePlaceId}`
: '';
url = prefixes['google-maps']
url += `?q=${useTitleForQuery ? encodedTitle : latlng}`
// url += (isIOS) ? '&api=1' : ''
url += (googlePlaceId) ? `&query_place_id=${googlePlaceId}` : ''

url += (useSourceDestiny) ? `&saddr=${sourceLatLng}` : ''
url += (useDstAddr) ? `&daddr=${encodedDstaddr}` : `&daddr=${latlng}`
url += '&directionsmode=driving'
break;
case 'citymapper':
url = `${prefixes.citymapper}directions?endcoord=${latlng}`;
Expand All @@ -116,15 +120,15 @@ export async function showLocation(options) {
}
break;
case 'uber':
url = `${prefixes.uber}?action=setPickup&dropoff[latitude]=${lat}&dropoff[longitude]=${lng}`;
url = `${prefixes['uber']}?action=setPickup`

if (title) {
url += `&dropoff[nickname]=${encodedTitle}`;
if (useDstAddr) {
url += `&dropoff[formatted_address]=${encodedDstaddr}`
} else {
url += `&dropoff[latitude]=${lat}&dropoff[longitude]=${lng}`
}

url += useSourceDestiny
? `&pickup[latitude]=${sourceLat}&pickup[longitude]=${sourceLng}`
: '&pickup=my_location';
url += (useSourceDestiny) ? `&pickup[latitude]=${sourceLat}&pickup[longitude]=${sourceLng}` : `&pickup=my_location`

break;
case 'lyft':
Expand All @@ -150,10 +154,11 @@ export async function showLocation(options) {
}
break;
case 'waze':
url = `${prefixes.waze}?ll=${latlng}&navigate=yes`;
if (title) {
url += `&q=${encodedTitle}`;
}
// url = `${prefixes.waze}?ll=${latlng}&navigate=yes`;
url = `${prefixes.waze}?`;
url += `&q=${encodedDstaddr}`;
url += `&navigate=yes`;

break;
case 'yandex':
url = `${prefixes.yandex}build_route_on_map?lat_to=${lat}&lon_to=${lng}`;
Expand Down