Get coordinates from a google maps link

A

Anonymous

Guest
Hello, can someone help me a little with an idea how to solve my issue?

I want to extract the coordonates from a google maps link simple by inserting the link after selecting a location.

Here are my examples :

https://www.google.com/…/data=!4m5!3m4!1s0x40b201bd6d879d9d…

if you notice, there are 2 sets of coordinates : 44.4412293 and 26.0417445 and at the end of the link 44.4443741 and 26.036514

I would like a method to extract both coordonates or at least the last ones from the end of the link. I managed with string to extract the first set of the coordonates but im having problems with the rest of them

If I didn’t make myself clear heres another example : https://www.google.com/…/data=!4m5!3m4!1s0x0:0x50c4b31e3c3c… should be : 44.4337449 and 26.0917408 44.4346072 26.0971856

Thank you,

Alex
 
You can get the first coordinates by this code
Code:
$string = "https://www.google.com/maps/place/New+York,+Spojen%C3%A9+st%C3%A1ty+americk%C3%A9/@40.6976637,-74.1197639,11z/data=!3m1!4b1!4m5!3m4!1s0x89c24fa5d33f083b:0xc80b8f06e177fe62!8m2!3d40.7127753!4d-74.0059728";

$coord1 = explode (",", $string);
$coord1_length = count ($coord1);
$coordinarion1 = explode ("@", $coord1[$coord1_length - 3]);
$coordinarion2 = $coord1[$coord1_length - 2];

echo $coordinarion1[1];
echo "<br>";
echo $coordinarion2;



And the second coordinates by this code
Code:
$string = "https://www.google.com/maps/place/New+York,+Spojen%C3%A9+st%C3%A1ty+americk%C3%A9/@40.6976637,-74.1197639,11z/data=!3m1!4b1!4m5!3m4!1s0x89c24fa5d33f083b:0xc80b8f06e177fe62!8m2!3d40.7127753!4d-74.0059728";

$test = explode ("d", $string);
$arr_length = count ($test);
$coord3 = explode ("!", $test[$arr_length - 2]);
$coord4 = $test[$arr_length-1];

echo $coord3[0];
echo "<br>";
echo $coord4;
 
Back
Top