Last active
August 4, 2021 11:13
-
-
Save PetraMotz/3bd26ad243df5c7434adb7a91c01acf1 to your computer and use it in GitHub Desktop.
PHP #openstreetmap #nominatim #lat #long #php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $markers = $this->markerRepository->findAll(); (vorher müssen die Marker mit Adresse usw in die DB Tabelle impportiert werden über PHP my admin) | |
| PID muss gesetzt werden! | |
| in den ensprechenden controller in die methode wo man die marker braucht: | |
| foreach ($markers as $marker) { | |
| if (!empty($marker->getLatitude()) || !empty($marker->getLongitude())) { | |
| continue; | |
| } | |
| $address = urlencode($marker->getAddress()); | |
| $search = "https://nominatim.openstreetmap.org/search.php?q={$address}&format=json"; | |
| $json = $this->getSslPage($search); | |
| $json = json_decode($json); | |
| $lat = $json[0]->lat ?? 0; (latidude oder 0) | |
| $long = $json[0]->lon ?? 0; | |
| $marker->setLatitude($lat); | |
| $marker->setLongitude($long); | |
| $this->markerRepository->update($marker); | |
| $this->objectManager->get(PersistenceManager::class)->persistAll(); | |
| } | |
| eigene funktion im controller: | |
| private function getSslPage($url) { | |
| $ch = curl_init(); | |
| curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); | |
| curl_setopt($ch, CURLOPT_HEADER, false); | |
| curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
| curl_setopt($ch, CURLOPT_URL, $url); | |
| curl_setopt($ch, CURLOPT_REFERER, $url); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
| $result = curl_exec($ch); | |
| curl_close($ch); | |
| return $result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment