I want to open a new tab showing the google map with specific marker styling and functionality. I am using reverse geocoding since I have the longitude and latitude data. I am able to open the map in same page but not able open it in a new window.
Thanks in advance
Here is my Curent Code:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Reverse Geocoding</title>
<style>
#map {
height: 100%;
}
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<input id="latlng" type="text" value="40.714224,-73.961452" >
<button id="submit" onclick="geocodeLatLng()">knvhcmc</button>
<div id="map"> </div>
<script>
function geocodeLatLng() {
debugger;
var input = document.getElementById('latlng').value;
var latlngStr = input.split(',', 2);
var latlng = {lat: parseFloat(latlngStr[0]), lng:
parseFloat(latlngStr[1])};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 8,
center: latlng
});
var geocoder = new google.maps.Geocoder;
var infowindow = new google.maps.InfoWindow;
geocoder.geocode({'location': latlng}, function(results, status) {
if (status === 'OK') {
if (results[0]) {
map.setZoom(11);
var marker = new google.maps.Marker({
position: latlng,
map: map
});
infowindow.setContent(results[0].formatted_address);
infowindow.open(map, marker);
var divText = document.getElementById("map").outerHTML;
var myWindow = window.open('', '', 'width=1000,height=800');
var doc = myWindow.document;
doc.open();
doc.write(divText);
} else {
window.alert('No results found');
}
} else {
window.alert('Geocoder failed due to: ' + status);
}
});
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?
key=AIzaSyCcyyWSd6ETju45EKjArNtJXAJt5w1xecQ&callback=initMap">
</script>
</body>
</html>