albeebe / PHP-FindMyiPhone

PHP class to locate, play sounds, and lock iOS devices
Other
79 stars 49 forks source link

Locate #12

Open NathanWilcox opened 7 years ago

NathanWilcox commented 7 years ago

Hi,

Where in the following code can I enter specific device id to return the location?

// This will print out all the devices on your account so you can grab the device IDs
    //$fmi->printDevices();

    // Find a device that is reporting its location and attempt to get its current location
    foreach ($fmi->devices as $device) {
        if ($device->location->timestamp != "") {
            // Locate the device
            $location = $fmi->locate($device->ID);

            print "Device <B>".$device->ID."</B> is located at <I>".$location->latitude.", ".$location->longitude."</I>";

            // Play a sound on the device
            //$fmi->playSound($device->ID, "You've been located!");

            // Lock the device
            //$fmi->lostMode($device->ID, "You got locked out", "555-555-5555");

            break;
        }
    }
?>

I would like to only request location of a specific device not all of them.

Thanks

philarkwright commented 7 years ago

Run the script above to find all devices. Then under ID column, copy the ID and then place into the code below where it says "device_id".

<?php
    include ("class.findmyiphone.php");
    $fmi = new FindMyiPhone("username", "password");
    $location = $fmi->locate("device_id", 30);
    $longitude = $location->longitude;
    $latitude = $location->latitude
?>
NathanWilcox commented 7 years ago

Hi @philarkwright

I've done the above but encountered the following error: PHP Notice: Undefined offset: 1 in /etc/openhab2/scripts/class.findmyiphone.php on line 261 PHP Notice: Undefined offset: 1 in /etc/openhab2/scripts/class.findmyiphone.php on line 261

The section this refers to in my class.findmyiphone.php looks like this:

  curl_setopt($ch, CURLOPT_HTTPHEADER, $arrHeaders);
  $response = curl_exec($ch);
  $info = curl_getinfo($ch);
  $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
  $responseBody = substr($response, $header_size);
  $headers = array();
  foreach (explode("\r\n", substr($response, 0, $header_size)) as $i => $line) {
      if ($i === 0)
          $headers['http_code'] = $info["http_code"];
      else {
          list ($key, $value) = explode(': ', $line);
          if (strlen($key) > 0)
              $headers[$key] = $value;
      }

With line 261 actually being:

list ($key, $value) = explode(': ', $line);

Any ideas on this?