Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Displaying image in google map

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 815
    Comment on it

    While showing the locations based on the latitude and longitude you need to display the images associated with that object you are displaying the locaton for.

     

     

     

     

    This is the database where we have stored the image information.

     

     

    So in that case you need to make the use of images either from the datasource or from the current project to be used into the google API map display.

     

     

      public string ConvertDataTabletoString()
        {
            DataTable dt = new DataTable();
            using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand("select title=Company,lat=latitude,lng=longitude,image from MapDimension", con))
                {
                    con.Open();
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    da.Fill(dt);
                    System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                    List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
                    Dictionary<string, object> row;
                    foreach (DataRow dr in dt.Rows)
                    {
                        row = new Dictionary<string, object>();
                        foreach (DataColumn col in dt.Columns)
                        {
                            row.Add(col.ColumnName, dr[col]);
                        }
                        rows.Add(row);
                    }
                    return serializer.Serialize(rows);
                }
            }

     

     

    function initialize() {
            var markers = JSON.parse('<%=ConvertDataTabletoString() %>');
            var mapOptions = {
            center: new google.maps.LatLng(markers[0].lat, markers[0].lng),
    zoom: 5,
    mapTypeId: google.maps.MapTypeId.ROADMAP
    //  marker:true
    };
    var infoWindow = new google.maps.InfoWindow();
    var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
    var image;
    for (i = 0; i < markers.length; i++) {
    var data = markers[i]
    var myLatlng = new google.maps.LatLng(data.lat, data.lng);
    
    var contentString = '<div id="content" style="margin-left:15px; margin-top:3px;overflow:hidden;">' +
    '<div id="bodyContent">' + '<img src=' + data.image + ' style="width:172px;height:45px;"  alt="WebStreet.in"/>' + '<br><font style="color:darkblue;font:11px tahoma;margin-left:5px;">' + data.title + ' Your Trusted IT Solutions Provider</font>' +
    '</div>' +
    '</div>';
    
    
    //var marker = new google.maps.Marker({
    
    //position: myLatlng,
    //map: map,
    //title: data.title,
    //});
    
    var marker = new google.maps.Marker({
        map: map,
        // draggable:true,
        // animation: google.maps.Animation.DROP,
        position: myLatlng,
        title: data.title,
        icon: '' // null = default icon
    });
    
    
        // Start of newly added code block
    
    var infowindow = new google.maps.InfoWindow({
        content: contentString,
        width: 192,
        height: 100
    });
    
    
    (function (marker, data) {
    
        // Attaching a click event to the current marker
        google.maps.event.addListener(marker, "click", function (e) {
            infoWindow.setContent(data.description);
            infowindow.open(map, marker);
        });
    
    
        //google.maps.event.addListener(marker, "mouseover", function (e) {
        //    infoWindow.setContent(data.description);
        //    infowindow.open(map, marker);
        //});
    
    
    
    })(marker, data);
    
    
    }
        
         
            // End of newly added code block
        }

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: