-1

I have map which was set up on server and based on google map. To embeded it to my webpage I used iframe. Now i need to get lat and long on click to map and than write data to my db. How can i get it?

Here is my iframe

<iframe src="https://my_domain/projects/?first=7&second=123&third=567" width="100%" height="350px" align="left" id="inneriframe" scrolling="no"></iframe>

Here is no initialize or else function that usualy i use for google map, thats why can not get it by functions.

Orik00
  • 73
  • 1
  • 9
  • Follow this [Link](https://stackoverflow.com/questions/17756493/accessing-users-latitude-and-longitude-when-loading-html5-geolocation-in-iframe). It will helpfull to you. – Sagar Shinde Aug 30 '18 at 10:31
  • @sagarshinde but it is different situation. i do not have any button, and not taking data from div. – Orik00 Aug 30 '18 at 12:04

1 Answers1

0

You can initialize the map on window.load and get the value using event addListener.

var map;
    function initialize() {
        var myLatlng = new google.maps.LatLng(24.18061975930,79.36565089010);
        var myOptions = {
            zoom:7,
            center: myLatlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        }
        map = new google.maps.Map(document.getElementById("gmap"), myOptions);
        // marker refers to a global variable
        marker = new google.maps.Marker({
            position: myLatlng,
            map: map
        });

        google.maps.event.addListener(map, "click", function(event) {
            // get lat/lon of click
            var clickLat = event.latLng.lat();
            var clickLon = event.latLng.lng();

           alert(clickLat.toFixed(5));
           alert(clickLon.toFixed(5));

              var marker = new google.maps.Marker({
                    position: new google.maps.LatLng(clickLat,clickLon),
                    map: map
                 });
        });
}   

window.onload = function () { initialize() };
Sagar Shinde
  • 150
  • 10