Найти лат и ланг в этом маршруте Google map API PHP - PullRequest
0 голосов
/ 25 сентября 2019

Я не могу найти эффективное решение для соответствия маршрутам.Пример: Пользователь 1 перемещается из А в D. Пользователь 2 из В в С.Теперь у меня есть ответы направления от API карты Google (предпочтительно объектов JSON), в котором содержится информация обо всех точках в двух маршрутах.Теперь мне нужно найти, если маршрут от B до C между A и D.

Exmple

Я пытаюсь эту программу.но не удовлетворены, пожалуйста, проверьте это.найти lat и lang в этом маршруте.

enter code here
$start = "9.916615,78.111638";
$end = "9.944564,78.156068";

$url = "https://maps.googleapis.com/maps/api/directions/json?origin=" . $start . "&destination=" . $end . "&mode=driving&units=km&sensor=true&&language=pl-PL&key=" . MAP_KEY;
$geocode = @file_get_contents($url);
$response_a = json_decode($geocode);
$points = $this->get_polyline_points($response_a->routes[0]->overview_polyline->points);

$dxf = $this->searchForId('9.9166','78.1116', $points);

публичная функция get_polyline_points ($ point) {

# Do steps 1-11 given here 
# https://developers.google.com/maps/documentation/utilities/polylinealgorithm
# in reverse order and inverted (i.e. left shift -> right shift, add -> subtract)

$string = $point;
# Step 11) unpack the string as unsigned char 'C'
$byte_array = array_merge(unpack('C*', $string));
$results = array();

$index = 0; # tracks which char in $byte_array
do {
  $shift = 0;
  $result = 0;
  do {
    $char = $byte_array[$index] - 63; # Step 10
    # Steps 9-5
    # get the least significat 5 bits from the byte
    # and bitwise-or it into the result
    $result |= ($char & 0x1F) << (5 * $shift);
    $shift++; $index++;
  } while ($char >= 0x20); # Step 8 most significant bit in each six bit chunk
    # is set to 1 if there is a chunk after it and zero if it's the last one
    # so if char is less than 0x20 (0b100000), then it is the last chunk in that num

  # Step 3-5) sign will be stored in least significant bit, if it's one, then 
  # the original value was negated per step 5, so negate again
  if ($result & 1)
    $result = ~$result;
  # Step 4-1) shift off the sign bit by right-shifting and multiply by 1E-5
  $result = ($result >> 1) * 0.00001;
  $results[] = $result;
} while ($index < count($byte_array));

# to save space, lat/lons are deltas from the one that preceded them, so we need to 
# adjust all the lat/lon pairs after the first pair
for ($i = 2; $i < count($results); $i++) {
  $results[$i] += $results[$i - 2];
}

# chunk the array into pairs of lat/lon values
return array_chunk($results, 2);

# Test correctness by using Google's polylineutility here:
# https://developers.google.com/maps/documentation/utilities/polylineutility

}

enter code here

функция searchForId ($ key1,$ key2, $ array) {foreach ($ array as $ key => $ val) {if (! (strpos ($ val ['0'], $ key1) === false) &&! (strpos ($ val ['1'], $ key2) === false)) {return $ key;}} return null;}

...