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>
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>
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'];
});
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us