When the page is loaded on the map after determining the geolocation (html5) a marker appears.

Task: after it has appeared, when dragging a card, it must always be in the center (i.e., the card is dragged, and this marker remains in the center all the time).

    2 answers 2

    You can call: map.getCenter() this will return the content object Lon, Lat.

    And this is how you can get coordinates by pressing the right mouse button:

     google.maps.event.addListener(map, "rightclick", function(event) { var lat = event.latLng.lat(); var lng = event.latLng.lng(); ... }); 
    • Thank you! I figured out the center .... Tepert still can't do it so that this initial marker remains all-time in the center of the map while it is being dragged back and forth ... He then runs after the cursor, then they breed when dragging. .. Eh-eh-eh ... - Alexander
    • @ Alexander start a new question, show the code. - Mstislav Pavlov
     google.maps.event.addListener(map, "dragend", function(event) { var g = map.getCenter(); $('#lat').html(g.lat()); $('#long').html(g.lng()); coords = new google.maps.LatLng(g.lat(), g.lng()); marker.setPosition(g); }); 

    That's how it works!))) Thank you!

    • All the same, I did not achieve the necessary "magic" (((I will create a new question ... - Alexander