Squashed commit of the following:
commit 02c0896ab21422c7b2ee63ad87276de97d2649d1 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Mon Oct 17 20:55:08 2016 +0100 Add change to log commit 05946ce17bf81f4965da4c241c8b636b81fb15cd Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Mon Oct 17 19:06:22 2016 +0100 The docs implied a different format response, adjusting my code to the actual response commit 55e3fab71eed3d44591d3742a9e30ae840427d2c Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Mon Oct 17 17:16:07 2016 +0100 Add a missing bracket/semi-colon to end of return statement commit 08c5b687db7228ebbecb0cd975857c886c6e0851 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Mon Oct 17 17:10:42 2016 +0100 Only add a map for actual places commit eef45a3ab36015ffd3ce1129afd15f570e4e8496 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Mon Oct 17 17:08:24 2016 +0100 Allow a name to be used instead of co-ordinates
This commit is contained in:
parent
79a64a4b9f
commit
e316f98e26
3 changed files with 56 additions and 8 deletions
|
@ -2,14 +2,15 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Cache;
|
|
||||||
use Twitter;
|
use Twitter;
|
||||||
use App\Tag;
|
use App\Tag;
|
||||||
use App\Note;
|
use App\Note;
|
||||||
use HTMLPurifier;
|
use HTMLPurifier;
|
||||||
|
use GuzzleHttp\Client;
|
||||||
use HTMLPurifier_Config;
|
use HTMLPurifier_Config;
|
||||||
use Jonnybarnes\IndieWeb\Numbers;
|
use Jonnybarnes\IndieWeb\Numbers;
|
||||||
use Illuminate\Filesystem\Filesystem;
|
use Illuminate\Filesystem\Filesystem;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Jonnybarnes\WebmentionsParser\Authorship;
|
use Jonnybarnes\WebmentionsParser\Authorship;
|
||||||
|
|
||||||
// Need to sort out Twitter and webmentions!
|
// Need to sort out Twitter and webmentions!
|
||||||
|
@ -40,9 +41,7 @@ class NotesController extends Controller
|
||||||
$latlng = explode(',', $pieces[0]);
|
$latlng = explode(',', $pieces[0]);
|
||||||
$note->latitude = trim($latlng[0]);
|
$note->latitude = trim($latlng[0]);
|
||||||
$note->longitude = trim($latlng[1]);
|
$note->longitude = trim($latlng[1]);
|
||||||
if (count($pieces) == 2) {
|
$note->address = $this->reverseGeoCode((float) trim($latlng[0]), (float) trim($latlng[1]));
|
||||||
$note->address = $pieces[1];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ($note->place !== null) {
|
if ($note->place !== null) {
|
||||||
$lnglat = explode(' ', $note->place->location);
|
$lnglat = explode(' ', $note->place->location);
|
||||||
|
@ -129,9 +128,7 @@ class NotesController extends Controller
|
||||||
$latlng = explode(',', $pieces[0]);
|
$latlng = explode(',', $pieces[0]);
|
||||||
$note->latitude = trim($latlng[0]);
|
$note->latitude = trim($latlng[0]);
|
||||||
$note->longitude = trim($latlng[1]);
|
$note->longitude = trim($latlng[1]);
|
||||||
if (count($pieces) == 2) {
|
$note->address = $this->reverseGeoCode((float) trim($latlng[0]), (float) trim($latlng[1]));
|
||||||
$note->address = $pieces[1];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ($note->place !== null) {
|
if ($note->place !== null) {
|
||||||
$lnglat = explode(' ', $note->place->location);
|
$lnglat = explode(' ', $note->place->location);
|
||||||
|
@ -280,4 +277,52 @@ class NotesController extends Controller
|
||||||
|
|
||||||
return $purifier->purify($html);
|
return $purifier->purify($html);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do a reverse geocode lookup of a `lat,lng` value.
|
||||||
|
*
|
||||||
|
* @param float The latitude
|
||||||
|
* @param float The longitude
|
||||||
|
* @return string The location name
|
||||||
|
*/
|
||||||
|
public function reverseGeoCode(float $latitude, float $longitude): string
|
||||||
|
{
|
||||||
|
$latlng = $latitude . ',' . $longitude;
|
||||||
|
|
||||||
|
return Cache::get($latlng, function () use ($latlng, $latitude, $longitude) {
|
||||||
|
$guzzle = new Client();
|
||||||
|
$response = $guzzle->request('GET', 'https://nominatim.openstreetmap.org/reverse', [
|
||||||
|
'query' => [
|
||||||
|
'format' => 'json',
|
||||||
|
'lat' => $latitude,
|
||||||
|
'lon' => $longitude,
|
||||||
|
'zoom' => 18,
|
||||||
|
'addressdetails' => 1,
|
||||||
|
],
|
||||||
|
'headers' => ['User-Agent' => 'jonnybarnes.uk via Guzzle, email jonny@jonnybarnes.uk']
|
||||||
|
]);
|
||||||
|
$json = json_decode($response->getBody());
|
||||||
|
if (isset($json->address->town)) {
|
||||||
|
$address = $json->address->town . ', ' . $json->address->country;
|
||||||
|
Cache::forever($latlng, $address);
|
||||||
|
|
||||||
|
return $address;
|
||||||
|
}
|
||||||
|
if (isset($json->address->city)) {
|
||||||
|
$address = $json->address->city . ', ' . $json->address->country;
|
||||||
|
Cache::forever($latlng, $address);
|
||||||
|
|
||||||
|
return $address;
|
||||||
|
}
|
||||||
|
if (isset($json->address->county)) {
|
||||||
|
$address = $json->address->county . ', ' . $json->reversegeocode->country;
|
||||||
|
Cache::forever($latlng, $address);
|
||||||
|
|
||||||
|
return $address;
|
||||||
|
}
|
||||||
|
Cache::forever($latlng, $json->address->country);
|
||||||
|
|
||||||
|
return $json->reversegeocode->addressparts->country;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## Version {next}
|
||||||
|
- Allow co-ordinates to be used for note location, reverse geocode place name will be used (w/o map)
|
||||||
|
|
||||||
## Version 0.0.14.2 (2016-10-17)
|
## Version 0.0.14.2 (2016-10-17)
|
||||||
- Update .lock, particularly trying to get medialibrary working
|
- Update .lock, particularly trying to get medialibrary working
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
@if($note->address)<span class="note-address p-location">in @if($note->placeLink)<a href="{{ $note->placeLink }}">@endif<span class="p-name">{{ $note->address }}</span>@if($note->placeLink)</a>@endif</span>@endif
|
@if($note->address)<span class="note-address p-location">in @if($note->placeLink)<a href="{{ $note->placeLink }}">@endif<span class="p-name">{{ $note->address }}</span>@if($note->placeLink)</a>@endif</span>@endif
|
||||||
@if($note->replies > 0)Replies: {{ $note->replies }}@endif
|
@if($note->replies > 0)Replies: {{ $note->replies }}@endif
|
||||||
@if($note->tweet_id)@include('templates.social-links', ['tweet_id' => $note->tweet_id, 'nb60id' => $note->nb60id])@endif
|
@if($note->tweet_id)@include('templates.social-links', ['tweet_id' => $note->tweet_id, 'nb60id' => $note->nb60id])@endif
|
||||||
@if ($note->latitude)
|
@if ($note->placeLink)
|
||||||
<div class="map" data-latitude="{{ $note->latitude }}" data-longitude="{{ $note->longitude }}"></div>
|
<div class="map" data-latitude="{{ $note->latitude }}" data-longitude="{{ $note->longitude }}"></div>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue