yii2-google-maps-library
yii2-google-maps-library copied to clipboard
Get Lat Long from map
Hii 2amigos, can i use this library for location picker? like get the lat long from marker i set. Thanks
Hi @anim007 in order to place a marker, you need to know lat,lon. So I don't really understand your question but if you wish to get the location when the marker has been moved. Then I highly recommend that you append your custom JS to the widget so you can effectively get the current location of the marker.
just add Event on "dragend" to the Marker
<?php
$marker_dragend_event_js = <<<JS
document.getElementById('latitude_input').value = event.latLng.lat();
document.getElementById('longitude_input').value = event.latLng.lng();
JS;
$marker = new Marker([
'position' => new LatLng(['lat' => 39.7200, 'lng' => 2.9116]),
'draggable' => true,
'title' => 'Marker',
'events' => [
new Event([
'trigger' => 'dragend',
'js' => $marker_dragend_event_js,
]),
],
]);