Naitik Patel
Naitik Patel

Reputation: 89

Google map not properly load in web browser control

I have one html file like Map.Html

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <title></title>
    <script type="text/javascript" src="http://maps.google.com.mx/maps/api/js?sensor=true"></script>
    <script type="text/javascript">

        var geocoder;
        var map;

        function initialize() {

            geocoder = new google.maps.Geocoder();

            var myOptions = {
                zoom: 8,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            }

            var address = "Ahmedabad, India" //change the address in order to search the google maps

            geocoder.geocode({ 'address': address }, function (results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    map.setCenter(results[0].geometry.location);
                    var marker = new google.maps.Marker({
                        map: map,
                        position: results[0].geometry.location
                    });

                    var infoWindow = new google.maps.InfoWindow({
                        content: 'Hello'
                    });

                    google.maps.event.addListener(marker, "click", function (e) {
                        infoWindow.open(map, marker);
                    });

                } else {
                    alert("Geocode was not successful for the following reason: " + status);
                }
            });

            map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
        }
    </script>
</head>
<body onload="initialize()">
    <div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>

then i load this html file in webbrowser control DocumentText using below code:

using (StreamReader reader = new StreamReader(System.Windows.Forms.Application.StartupPath + "\\Map.html"))
{
_mapHTML = reader.ReadToEnd();
}
webBrowser1.DocumentText = _mapHTML;

but map not load properly. zoom in/out, Map/Satellite option, Marker are showing but one white layer on map display.

Upvotes: 1

Views: 1118

Answers (1)

M Potter
M Potter

Reputation: 11

SOLVED -- for me at least.

For some reason, the Webbrowser control is defaulting to a bad version (experimental?). I changed my initialization script to specify the current 3.3 version and everything is back to normal.

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.3"></script>

Upvotes: 1

Related Questions