How to send Leaflet latlng to other page

27 views
Skip to first unread message

Kiran Patil

unread,
Jul 29, 2016, 11:14:01 AM7/29/16
to Leaflet
Hi,

I have  index.html.erb and main.js, if I click on the marker on the map I should get the latlng on the text fields. But It is not working.

Can some one please guide me to resolve this issue ?

In index.html.erb which is Rails view I have button to open Leaflet map on new window and defined text fields to get latlng after clicking on the marker
------------
<%= button_to('Assets', {:action => 'view_asset'}, {:onclick => "this.form.target = 'mywin'; window.open('','mywin', 'height = 650, width = 750, top = 20, left = 100, scrollbars = 0, toolbar = 0, status = 0, menubar = 0, location = 0')"}) %>

<input
id="userLat" type="text" name="val-lat" value="User Latitude" /> <input id="userLng" type="text" name="val-lng" value="User Longitude" />

In main.js
--------------
$('document').ready(function() {

var mymap = L.map('map1').setView([12.9773, 77.5712], 10);
mymap.setZoom(16);

L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(mymap);

var ll1
ll1 = [12.9773, 77.5712]

var marker = L.marker(ll1).on('click', markerOnClick).addTo(mymap);

function markerOnClick(e)
{
var ll = marker.getLatLng();
alert(ll);
document.querySelector('#userLat').value = ll.lat;
document.querySelector('#userLng').value = ll.lng;

}

}

Regards,
Kiran.

Kiran Patil

unread,
Jul 29, 2016, 9:59:13 PM7/29/16
to Leaflet
I got the solution and it is very simple, until I know :).

$("#userLng", opener.window.document).val(ll.lng);

Please help me to open a second map on new window2, already first is opened in window1.

Thanks.
Reply all
Reply to author
Forward
0 new messages