Skip to content

Commit 9cfa5d3

Browse files
committed
changed getPosition
1 parent 70864c9 commit 9cfa5d3

File tree

1 file changed

+46
-41
lines changed

1 file changed

+46
-41
lines changed

src/Providers/Api/GoogleMaps.php

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Embed\Adapters\Adapter;
66
use Embed\Providers\Provider;
7+
use Embed\Http\Url;
78
use Embed\Utils;
89

910
/**
@@ -59,45 +60,6 @@ public function getTitle()
5960
}
6061
}
6162

62-
/**
63-
* Returns parsed position data from url.
64-
*
65-
* @return array
66-
*/
67-
private function getPosition()
68-
{
69-
$url = $this->adapter->getResponse()->getUrl();
70-
71-
// Set defaults
72-
$position = [
73-
'coordinates' => '',
74-
'zoom' => '4',
75-
'heading' => '0',
76-
'pitch' => '0',
77-
'fov' => '90'
78-
];
79-
80-
if ($this->mode === 'view') {
81-
$pos = explode(",", $url->getDirectoryPosition(1));
82-
$position['coordinates'] = str_replace('@','',$pos[0]).','.$pos[1];
83-
$position['zoom'] = str_replace('z',"",$pos[2]);
84-
}
85-
86-
if ($this->mode === 'streetview') {
87-
$pos = explode(",", $url->getDirectoryPosition(1));
88-
$position['coordinates'] = str_replace('@','',$pos[0]).','.$pos[1];
89-
$position['zoom'] = str_replace('a','',$pos[2]); // seems not used by google (emulated by other params)
90-
$position['heading'] = str_replace('h','',$pos[4]);
91-
$position['fov'] = str_replace('y','',$pos[3]);
92-
$pitch = str_replace('t','',$pos[5]); // t is pitch but in 180% format
93-
if (is_numeric($pitch)) {
94-
$position['pitch'] = floatval($pitch) - 90;
95-
}
96-
}
97-
98-
return $position;
99-
}
100-
10163
/**
10264
* {@inheritdoc}
10365
*/
@@ -120,7 +82,8 @@ public function getCode()
12082

12183
switch ($this->mode) {
12284
case 'view':
123-
$pos = $this->getPosition();
85+
$pos = self::getPosition($this->mode, $url);
86+
12487
return Utils::iframe($url
12588
->withPath('maps/embed/v1/'.$this->mode)
12689
->withQueryParameters([
@@ -130,7 +93,8 @@ public function getCode()
13093
]));
13194

13295
case 'streetview':
133-
$pos = $this->getPosition();
96+
$pos = self::getPosition($this->mode, $url);
97+
13498
return Utils::iframe($url
13599
->withPath('maps/embed/v1/'.$this->mode)
136100
->withQueryParameters([
@@ -160,4 +124,45 @@ public function getCode()
160124
]));
161125
}
162126
}
127+
128+
/**
129+
* Returns parsed position data from url.
130+
*
131+
* @param string $mode The url mode
132+
* @param Url $url
133+
*
134+
* @return array
135+
*/
136+
private static function getPosition($mode, Url $url)
137+
{
138+
// Set defaults
139+
$position = [
140+
'coordinates' => '',
141+
'zoom' => '4',
142+
'heading' => '0',
143+
'pitch' => '0',
144+
'fov' => '90'
145+
];
146+
147+
if ($mode === 'view') {
148+
$pos = explode(",", $url->getDirectoryPosition(1));
149+
$position['coordinates'] = str_replace('@','',$pos[0]).','.$pos[1];
150+
$position['zoom'] = str_replace('z',"",$pos[2]);
151+
}
152+
153+
if ($mode === 'streetview') {
154+
$pos = explode(",", $url->getDirectoryPosition(1));
155+
$position['coordinates'] = str_replace('@','',$pos[0]).','.$pos[1];
156+
$position['zoom'] = str_replace('a','',$pos[2]); // seems not used by google (emulated by other params)
157+
$position['heading'] = str_replace('h','',$pos[4]);
158+
$position['fov'] = str_replace('y','',$pos[3]);
159+
$pitch = str_replace('t','',$pos[5]); // t is pitch but in 180% format
160+
if (is_numeric($pitch)) {
161+
$position['pitch'] = floatval($pitch) - 90;
162+
}
163+
}
164+
165+
return $position;
166+
}
167+
163168
}

0 commit comments

Comments
 (0)