TeslaSwift icon indicating copy to clipboard operation
TeslaSwift copied to clipboard

ShareToVehicleOptions: Add option to send GPS coordinates as destination

Open Krillle opened this issue 3 years ago • 2 comments

Some places on earth don't have regulate street address, especially charging stations along highway. So it would be great to share to vehicle geo coordinates (GPS) as a destination.

As far as I unterstand the ShareToVehicleOptions, this is not possible now, or is it?

While most applications apparently send a postal address to the car, the Google Maps application is sending precise geo coordinates. So the Tesla API seems to accept them.

Krillle avatar Nov 19 '22 13:11 Krillle

This gives a hint how to do it, unfortunately no further explained:

API: https://owner-api.teslamotors.com/api/1/vehicles/{remote_id}/command/share

Post JSON:


{
  "type": "share_ext_content_raw",
  "value": {
    "android.intent.extra.TEXT": "{There is no subject, only lng and lat}"
  },
  "locale": "zh-CN"
}

// Just put the latlon value and that's it. No prefix or tag is needed.

See https://github.com/timdorr/tesla-api/issues/188#issuecomment-624065809

Krillle avatar Nov 19 '22 21:11 Krillle

Did you figure out the data needed?

jonasman avatar Apr 30 '23 21:04 jonasman

@Krillle this seems easy to implement is "{There is no subject, only lng and lat}" just "{1.2,3.4}" ?

jonasman avatar Mar 08 '24 00:03 jonasman

so i added this to the master branch, give it a try as im not able to right now. If it is buggy we can fix it

jonasman avatar Mar 08 '24 00:03 jonasman

I added the feature my app Charge My Way and currently testing. I will let you know, when beta testers report it is working well.

Btw @jonasman if you like to have my app as a beta tester, let me now.

Krillle avatar Apr 12 '24 10:04 Krillle

@jonasman thanks for catching up with my idea. I implemented sending coordinate with TeslaSwift version 11.1.2. Beta testers report, it is nicely working. I will be back at my own car on Thursday and can test it myself by then.

static func sendCoordinate (coordinate: CLLocationCoordinate2D) {
  if let vehicle = Tesla.car.vehicle {
      let shareToVehicleOptions = ShareToVehicleOptions(coordinate: coordinate)
      Task {
          do {
              let _ = try await Tesla.api.sendCommandToVehicle(vehicle, command: VehicleCommand.shareToVehicle(options: shareToVehicleOptions))
              print("TESLA API: Coordinate sent", coordinate)
          } catch let error {
              print("TESLA API: Sending coordinate failed:", error)
          }
      }
  }
}

Log Output: TESLA API: Coordinate sent CLLocationCoordinate2D(latitude: 51.888644, longitude: 13.836824)

Krillle avatar Apr 13 '24 15:04 Krillle

I can confirm testing on my own car: It's working nicely.

Krillle avatar Apr 19 '24 14:04 Krillle

@Krillle i would like to test

jonasman avatar Apr 19 '24 15:04 jonasman