yii2-google-maps-library icon indicating copy to clipboard operation
yii2-google-maps-library copied to clipboard

Get Lat Long from map

Open anim007 opened this issue 7 years ago • 2 comments

Hii 2amigos, can i use this library for location picker? like get the lat long from marker i set. Thanks

anim007 avatar Oct 11 '17 05:10 anim007

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.

tonydspaniard avatar Dec 06 '17 04:12 tonydspaniard

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,
        ]),
     ],
]);

acidka avatar Jan 01 '18 16:01 acidka