Search code examples
laravelgoogle-mapscoordinatesgoogle-maps-markerslatitude-longitude

Get Co-ordinates based on the marker location over the google map


Aoa,

I am working on a web application where a shop vendor must put a latitude and longitude of his/her shop. It is easy to get if he/she is using application from the shop. But if he/she is somewhere else i want to show a map option to the vendor where he/she could search his/her shop point it. And I could get co-ordinates from that marker position.

I have studied google map api found a lot of useful things but couldn't understand how to achieve this as I am unable to find anything regarding getting co-ordinates from the marker.

It will be great if anybody could guide me that where should I look or what should I study to solve my issue.

Thanks in advance..


Solution

  • You can use the Maps JavaScript API to put a marker every time a certain point in the map was clicked then get the coordinates of the point and display it so that your user can directly get the exact coordinate of the marker. Here is a simple code I made to demonstrate this.

    In the code, I used a listener to the map to check for every click on the map and put a marker on it. It will then update the label display with the coordinate of the marker.

     map.addListener('click', function(event) {
        addMarker(event.latLng);
        document.getElementById("text").innerHTML = event.latLng.lat() + ',' + event.latLng.lng();
      });
    

    Hope this helps!