Show location on Google map in image format examples




Show location on Google map in image format examples

<!DOCTYPE html>
<html>
<head>
<title>Example of Showing Geolocation on Google Map</title>
<script type="text/javascript">
    function showPosition(){
        navigator.geolocation.getCurrentPosition(showMap);
    }
    
    function showMap(position){
        var latlong = position.coords.latitude + "," + position.coords.longitude;
        
        var mapLink = "https://maps.googleapis.com/maps/api/staticmap?center="+latlong+"&zoom=16&size=400x300&output=embed";
        
        // Create and insert Google map
        document.getElementById("embedMap").innerHTML = "<img alt='Map Holder' src='"+ mapLink +"'>";
    }
</script>
</head>
<body>
    <button type="button" onclick="showPosition();">Show My Position on Google Map</button>
    <div id="embedMap">
    </div>
</body>
</html>

Output