Answers for "get location namefrom latitude and longitude google map api javascript"

3

open google map with latitude and longitude javascript

// The best way is to use q parameter so that it displays the map with the point marked. eg.:

https://maps.google.com/?q=<lat>,<lng>
Posted by: Guest on January-20-2021
1

create google map latitude longitude API

function initMap() {
    const myLatlng = {
      lat: 21.7645,
      lng: 72.1519
    };
    const map = new google.maps.Map(document.getElementById("map"), {
      zoom: 10,
      center: myLatlng,
    });
    // Create the initial InfoWindow.
    let infoWindow = new google.maps.InfoWindow({
      content: "Click the map to get Lat/Lng!",
      position: myLatlng,
    });

    infoWindow.open(map);
    const marker = new google.maps.Marker({
    position: myLatlng,
    map,
    title: "Click to zoom",
  });
    map.addListener("center_changed", () => {
    // 3 seconds after the center of the map has changed, pan back to the
    // marker.
    window.setTimeout(() => {
      map.panTo(marker.getPosition());
    }, 3000);
  });

    // Configure the click listener.
    map.addListener("click", (mapsMouseEvent) => {

      // Close the current InfoWindow.
      infoWindow.close();
      // Create a new InfoWindow.
      infoWindow = new google.maps.InfoWindow({
        position: mapsMouseEvent.latLng,
      
      });

      infoWindow.setContent(
        JSON.stringify(mapsMouseEvent.latLng.toJSON(), null, 2)
      );
      infoWindow.open(map);

      const data = JSON.stringify(mapsMouseEvent.latLng.toJSON(), null, 2);
      const obj = JSON.parse(data);
      console.log(obj);

      // display in textbox
      document.getElementById("latitude").value = obj['lat'];
      document.getElementById("longitude").value = obj['lng'];
      
    });
  }
Posted by: Guest on September-17-2021

Code answers related to "get location namefrom latitude and longitude google map api javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language