question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onDragend and getting the new LatLng of the center of the map

See original GitHub issue

I’ve a basic map…

<Map
        google={google}
        zoom={13}
        style={mapStyles}
        initialCenter={userCoordinates}
        onClick={this.onMapClick}
        styles={style}
        onDragend={this.centerMoved}
      />

thing to note is the onDragend property… I have it mapped to fire this.centerMoved… which is defined as such. I can’t seem to figure out how to get the new map’s Lat and Lng at this point…

centerMoved = (mapProps, map) => {
    console.log(mapProps.google.maps.LatLng()); // returns undefined
};

Is there any way to get this information? Am I using the wrong event?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:7

github_iconTop GitHub Comments

2reactions
shivamjjhacommented, Aug 9, 2020
centerMoved(mapProps, map) {
        console.log('args:', mapProps, map);
        console.log(map.getCenter().lat());
}
2reactions
VicEsquivelcommented, Feb 27, 2020

@matgargano your center moved function should be like this:

centerMoved = (mapProps, map) => {
    console.log('center: '+map.getCenter());
    console.log('center: '+map.center);
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get lat, long after map dragend - Stack Overflow
The map dragend event callback function doesn't have any arguments. Inside the callback function, get the map center (which is what you want):...
Read more >
Getting Lat/Lng from a Click Event | Maps JavaScript API
This example listens for the click event, gets the latitude and longitude ... infoWindow = new google.maps.InfoWindow({ position: mapsMouseEvent.latLng, });
Read more >
Google Maps Reference - W3Schools
The Map() constructor creates a new map inside a specified HTML element (typically a ... getCenter(), LatLng, Returns the lat/lng of the center...
Read more >
Getting coordinates from click or drag event in Google Maps ...
getElementById('mapCanvas'), { zoom: 8, center: latLng, mapTypeId: google.maps.MapTypeId.ROADMAP }); var marker = new google.maps.Marker({ position: latLng ...
Read more >
How to Get formatted Address, Latitude, and Longitude from ...
How to Get formatted Address, Latitude, and Longitude from Dragged ... How to create a draggable marker on Google Map ... center: myLatlng,....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found