JavaScript Drag and drop marker in google maps drag drop marker google maps,drag and drop marker google

i want to create marker on google map through dragging marker image from outside the map canvas and drop it inside the canvas, i've registered dom event listener of google maps but inside the listener i have no access to latLng object, how do i find the latLng of dropping point?

<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
    <title>Active Users</title>
    <link type="text/css" rel="stylesheet" target='_blank' href="style.css" />
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>

    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=maps&sensor=false"></script>
    <script src="js/script.js"></script>
</head>
<body>
    <div id="big_wrapper">
        <div id="gmap_canvas" ondragover="allowDrop(event)"></div>
        <div id="controls">
           <div class="command">
              Coordinates: <br />
              <input type="text" id="lat" value="33.718629" /><br />

              <input type="text" id="lng" value="73.059082" /><br />
              <input type="button" value="Go" id="go" />
           </div>

           <div class="command">
               Markers: <br />
               <img src="img/marker.png" id="draggable" draggable="true" ondragstart="drag(event)" />
           </div>
           <div class="command" id="debug">
           </div>
        </div>
    </div>
</body>
<html>

and here is my javascript code

var geocoder;
var map;

$(function() {

    $("#go").click(function()
    {
        map.setCenter(new google.maps.LatLng($("#lat").val(), $("#lng").val()));
    });


});

function initialize() {
    // prepare Geocoder
    geocoder = new google.maps.Geocoder();

    var myLatlng = new google.maps.LatLng(33.718629,73.059082);

    var myOptions = { // default map options
        zoom: 2,
        center: myLatlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    map = new google.maps.Map(document.getElementById('gmap_canvas'), myOptions);
    mapDiv = document.getElementById('gmap_canvas');

    google.maps.event.addListener(map, 'dragend', function(event)
    {
        document.getElementById('lat').value = map.getCenter().lat();
        document.getElementById('lng').value = map.getCenter().lng();
    });

    google.maps.event.addListener(map, 'click', function(e)
    {
        alert(e.latLng);
    });

    google.maps.event.addDomListener(mapDiv, 'drop', function(event)
    {
        alert(event);
        google.maps.event.trigger(map, 'click');
    });
}

function allowDrop(ev)
{
    ev.preventDefault();
}

function drag(ev)
{
    ev.dataTransfer.setData("Text",ev.target.id);
}

function drop(ev)
{
    ev.preventDefault();
    var data=ev.dataTransfer.getData("Text");
    alert(ev.latLng);
}

// initialization
google.maps.event.addDomListener(window, 'load', initialize);
Answer:1

Is there any function of Javascript or Jquery to make a button clicked by code? I already search on the internet but didn't see the answer for this. Thanks so much!

Is there any function of Javascript or Jquery to make a button clicked by code? I already search on the internet but didn't see the answer for this. Thanks so much!

  1. button onclick code
  2. button onclick code behind c#
  3. button onclick code in android studio
  4. button onclick code in html
  5. button onclick code unity
  6. button onclick code behind
  7. button onclick code in c#
  8. button onclick code android

Using Google Chrome (v42) and the native webcomponents support, I am trying to use a custom element, where the custom element content sometimes contains inlined javascript tags. However, the parser ...

Using Google Chrome (v42) and the native webcomponents support, I am trying to use a custom element, where the custom element content sometimes contains inlined javascript tags. However, the parser ...

  1. web component custom element
  2. web component custom element example
  3. @webcomponents/custom-elements npm
  4. @webcomponents/custom-elements/src/native-shim
  5. web component vs custom element

This is probably a trivial question, but I'm trying to look for the most efficient way to do this. I am given a string in this format "20130914" from a servlet and I need to create a javascript date ...

This is probably a trivial question, but I'm trying to look for the most efficient way to do this. I am given a string in this format "20130914" from a servlet and I need to create a javascript date ...

  1. javascript convert yyyymmdd to date
  2. javascript convert yyyymmdd to yyyy-mm-dd
  3. javascript convert yyyymmdd string to date
  4. javascript convert yyyymmdd
  5. js convert yyyymmdd to date
  6. convert yyyymmdd to date in javascript
  7. convert yyyymmdd to date js
  8. convert yyyymmdd to date javascript

With JavaScript or CoffeeScript, is there an easy way to test for the following: if (locals.messages.text === "somestring") { ... } Now this needs three things to be true: locals needs to exist, ...

With JavaScript or CoffeeScript, is there an easy way to test for the following: if (locals.messages.text === "somestring") { ... } Now this needs three things to be true: locals needs to exist, ...