@capgo/capacitor-launch-navigator 8.0.21 → 8.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -164,7 +164,7 @@ console.log('Icon failures:', failures);
164
164
 
165
165
  - **Coordinates Only**: This plugin only accepts latitude/longitude coordinates for navigation. Address strings are not supported.
166
166
  - **Address Geocoding**: If you need to convert addresses to coordinates, use [@capgo/capacitor-nativegeocoder](https://github.com/Cap-go/capacitor-nativegeocoder).
167
- - **Tesla**: `app: 'tesla'` shares a Google Maps directions link to the Tesla app. Android targets the Tesla app directly; iOS opens the native share sheet because iOS does not allow selecting another app's share extension programmatically.
167
+ - **Tesla**: `app: 'tesla'` shares a Google Maps position text to the Tesla app. Android targets the Tesla app directly; iOS opens the native share sheet because iOS does not allow selecting another app's share extension programmatically.
168
168
 
169
169
  ## Supported Navigation Apps
170
170
 
@@ -206,7 +206,7 @@ public class LaunchNavigator {
206
206
  case "gaode":
207
207
  return createGaodeIntent(lat, lon, startLat, startLon);
208
208
  case "tesla":
209
- return createTeslaIntent(lat, lon, startLat, startLon, transportMode);
209
+ return createTeslaIntent(lat, lon, destinationName);
210
210
  default:
211
211
  return null;
212
212
  }
@@ -484,40 +484,29 @@ public class LaunchNavigator {
484
484
  return intent;
485
485
  }
486
486
 
487
- private Intent createTeslaIntent(double lat, double lon, Double startLat, Double startLon, String transportMode) {
487
+ private Intent createTeslaIntent(double lat, double lon, String destinationName) {
488
488
  Intent intent = new Intent(Intent.ACTION_SEND);
489
489
  intent.setType("text/plain");
490
- intent.putExtra(Intent.EXTRA_TEXT, createGoogleMapsWebUrl(lat, lon, startLat, startLon, transportMode));
490
+ intent.putExtra(Intent.EXTRA_TEXT, createTeslaShareText(lat, lon, destinationName));
491
491
  intent.setPackage("com.teslamotors.tesla");
492
492
  return intent;
493
493
  }
494
494
 
495
- private String createGoogleMapsWebUrl(double lat, double lon, Double startLat, Double startLon, String transportMode) {
496
- String url = String.format(
497
- Locale.US,
498
- "https://www.google.com/maps/dir/?api=1&destination=%f,%f&travelmode=%s",
499
- lat,
500
- lon,
501
- getGoogleMapsTravelMode(transportMode)
502
- );
503
- if (startLat != null && startLon != null) {
504
- url += String.format(Locale.US, "&origin=%f,%f", startLat, startLon);
505
- }
506
- return url;
495
+ static String createTeslaShareText(double lat, double lon, String destinationName) {
496
+ return createTeslaShareLabel(destinationName) + "\n\n" + createGoogleMapsPositionUrl(lat, lon);
507
497
  }
508
498
 
509
- private String getGoogleMapsTravelMode(String transportMode) {
510
- switch (transportMode) {
511
- case "walking":
512
- return "walking";
513
- case "bicycling":
514
- return "bicycling";
515
- case "transit":
516
- return "transit";
517
- case "driving":
518
- default:
519
- return "driving";
499
+ static String createGoogleMapsPositionUrl(double lat, double lon) {
500
+ return String.format(Locale.US, "https://maps.google.com/?q=%.6f,%.6f", lat, lon);
501
+ }
502
+
503
+ private static String createTeslaShareLabel(String destinationName) {
504
+ if (destinationName == null) {
505
+ return "Dropped pin";
520
506
  }
507
+
508
+ String normalizedName = destinationName.trim().replaceAll("[\\r\\n]+", " ");
509
+ return normalizedName.isEmpty() ? "Dropped pin" : normalizedName;
521
510
  }
522
511
 
523
512
  public boolean isAppAvailable(String app) {
@@ -10,7 +10,7 @@ import com.getcapacitor.annotation.CapacitorPlugin;
10
10
  @CapacitorPlugin(name = "LaunchNavigator")
11
11
  public class LaunchNavigatorPlugin extends Plugin {
12
12
 
13
- private final String pluginVersion = "8.0.21";
13
+ private final String pluginVersion = "8.0.22";
14
14
 
15
15
  private LaunchNavigator implementation;
16
16
 
@@ -171,8 +171,7 @@ struct NavigationAppInfo {
171
171
  case "tesla":
172
172
  shareToTesla(
173
173
  destination: destination,
174
- start: start,
175
- transportMode: transportMode,
174
+ destinationName: destinationName,
176
175
  viewController: viewController,
177
176
  completion: completion
178
177
  )
@@ -493,8 +492,7 @@ struct NavigationAppInfo {
493
492
 
494
493
  private func shareToTesla(
495
494
  destination: CLLocationCoordinate2D,
496
- start: CLLocationCoordinate2D?,
497
- transportMode: String,
495
+ destinationName: String?,
498
496
  viewController: UIViewController?,
499
497
  completion: @escaping (Bool, String?) -> Void
500
498
  ) {
@@ -503,12 +501,10 @@ struct NavigationAppInfo {
503
501
  return
504
502
  }
505
503
 
506
- guard let url = googleMapsWebURL(destination: destination, start: start, transportMode: transportMode) else {
507
- completion(false, "Invalid Tesla share URL")
508
- return
509
- }
510
-
511
- let activityViewController = UIActivityViewController(activityItems: [url], applicationActivities: nil)
504
+ let activityViewController = UIActivityViewController(
505
+ activityItems: [teslaShareText(destination: destination, destinationName: destinationName)],
506
+ applicationActivities: nil
507
+ )
512
508
  activityViewController.popoverPresentationController?.sourceView = viewController.view
513
509
  activityViewController.completionWithItemsHandler = { _, completed, _, error in
514
510
  if let error = error {
@@ -523,31 +519,29 @@ struct NavigationAppInfo {
523
519
  viewController.present(activityViewController, animated: true)
524
520
  }
525
521
 
526
- private func googleMapsWebURL(
527
- destination: CLLocationCoordinate2D,
528
- start: CLLocationCoordinate2D?,
529
- transportMode: String
530
- ) -> URL? {
531
- var urlString = "https://www.google.com/maps/dir/?api=1&destination=\(destination.latitude),\(destination.longitude)&travelmode=\(googleMapsTravelMode(transportMode))"
532
-
533
- if let startCoord = start {
534
- urlString += "&origin=\(startCoord.latitude),\(startCoord.longitude)"
535
- }
522
+ func teslaShareText(destination: CLLocationCoordinate2D, destinationName: String?) -> String {
523
+ "\(teslaShareLabel(destinationName))\n\n\(googleMapsPositionURLString(destination: destination))"
524
+ }
536
525
 
537
- return URL(string: urlString)
526
+ func googleMapsPositionURLString(destination: CLLocationCoordinate2D) -> String {
527
+ let coordinates = String(
528
+ format: "%.6f,%.6f",
529
+ locale: Locale(identifier: "en_US_POSIX"),
530
+ destination.latitude,
531
+ destination.longitude
532
+ )
533
+ return "https://maps.google.com/?q=\(coordinates)"
538
534
  }
539
535
 
540
- private func googleMapsTravelMode(_ transportMode: String) -> String {
541
- switch transportMode {
542
- case "walking":
543
- return "walking"
544
- case "bicycling":
545
- return "bicycling"
546
- case "transit":
547
- return "transit"
548
- default:
549
- return "driving"
536
+ private func teslaShareLabel(_ destinationName: String?) -> String {
537
+ guard let destinationName = destinationName else {
538
+ return "Dropped pin"
550
539
  }
540
+
541
+ let normalizedName = destinationName
542
+ .trimmingCharacters(in: .whitespacesAndNewlines)
543
+ .replacingOccurrences(of: "[\\r\\n]+", with: " ", options: .regularExpression)
544
+ return normalizedName.isEmpty ? "Dropped pin" : normalizedName
551
545
  }
552
546
 
553
547
  private func encoded(_ value: String) -> String {
@@ -9,7 +9,7 @@ import MapKit
9
9
  */
10
10
  @objc(LaunchNavigatorPlugin)
11
11
  public class LaunchNavigatorPlugin: CAPPlugin, CAPBridgedPlugin {
12
- private let pluginVersion: String = "8.0.21"
12
+ private let pluginVersion: String = "8.0.22"
13
13
  public let identifier = "LaunchNavigatorPlugin"
14
14
  public let jsName = "LaunchNavigator"
15
15
  public let pluginMethods: [CAPPluginMethod] = [
@@ -1,15 +1,25 @@
1
1
  import XCTest
2
+ import MapKit
2
3
  @testable import LaunchNavigatorPlugin
3
4
 
4
5
  class LaunchNavigatorTests: XCTestCase {
5
- func testEcho() {
6
- // This is an example of a functional test case for a plugin.
7
- // Use XCTAssert and related functions to verify your tests produce the correct results.
6
+ func testTeslaShareTextUsesGoogleMapsPosition() {
7
+ let implementation = LaunchNavigator()
8
+ let destination = CLLocationCoordinate2D(latitude: 47.6205, longitude: -122.3493)
9
+
10
+ XCTAssertEqual(
11
+ "Space Needle\n\nhttps://maps.google.com/?q=47.620500,-122.349300",
12
+ implementation.teslaShareText(destination: destination, destinationName: "Space Needle")
13
+ )
14
+ }
8
15
 
16
+ func testTeslaShareTextFallsBackToDroppedPinLabel() {
9
17
  let implementation = LaunchNavigator()
10
- let value = "Hello, World!"
11
- let result = implementation.echo(value)
18
+ let destination = CLLocationCoordinate2D(latitude: 47.6205, longitude: -122.3493)
12
19
 
13
- XCTAssertEqual(value, result)
20
+ XCTAssertEqual(
21
+ "Dropped pin\n\nhttps://maps.google.com/?q=47.620500,-122.349300",
22
+ implementation.teslaShareText(destination: destination, destinationName: " \n ")
23
+ )
14
24
  }
15
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-launch-navigator",
3
- "version": "8.0.21",
3
+ "version": "8.0.22",
4
4
  "description": "Capacitor plugin which launches native route navigation apps for Android, iOS",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",