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
    • 849
    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.

     

     

    1. public string ConvertDataTabletoString()
    2. {
    3. DataTable dt = new DataTable();
    4. using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString))
    5. {
    6. using (SqlCommand cmd = new SqlCommand("select title=Company,lat=latitude,lng=longitude,image from MapDimension", con))
    7. {
    8. con.Open();
    9. SqlDataAdapter da = new SqlDataAdapter(cmd);
    10. da.Fill(dt);
    11. System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
    12. List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
    13. Dictionary<string, object> row;
    14. foreach (DataRow dr in dt.Rows)
    15. {
    16. row = new Dictionary<string, object>();
    17. foreach (DataColumn col in dt.Columns)
    18. {
    19. row.Add(col.ColumnName, dr[col]);
    20. }
    21. rows.Add(row);
    22. }
    23. return serializer.Serialize(rows);
    24. }
    25. }

     

     

    1. function initialize() {
    2. var markers = JSON.parse('<%=ConvertDataTabletoString() %>');
    3. var mapOptions = {
    4. center: new google.maps.LatLng(markers[0].lat, markers[0].lng),
    5. zoom: 5,
    6. mapTypeId: google.maps.MapTypeId.ROADMAP
    7. // marker:true
    8. };
    9. var infoWindow = new google.maps.InfoWindow();
    10. var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
    11. var image;
    12. for (i = 0; i < markers.length; i++) {
    13. var data = markers[i]
    14. var myLatlng = new google.maps.LatLng(data.lat, data.lng);
    15.  
    16. var contentString = '<div id="content" style="margin-left:15px; margin-top:3px;overflow:hidden;">' +
    17. '<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>' +
    18. '</div>' +
    19. '</div>';
    20.  
    21.  
    22. //var marker = new google.maps.Marker({
    23.  
    24. //position: myLatlng,
    25. //map: map,
    26. //title: data.title,
    27. //});
    28.  
    29. var marker = new google.maps.Marker({
    30. map: map,
    31. // draggable:true,
    32. // animation: google.maps.Animation.DROP,
    33. position: myLatlng,
    34. title: data.title,
    35. icon: '' // null = default icon
    36. });
    37.  
    38.  
    39. // Start of newly added code block
    40.  
    41. var infowindow = new google.maps.InfoWindow({
    42. content: contentString,
    43. width: 192,
    44. height: 100
    45. });
    46.  
    47.  
    48. (function (marker, data) {
    49.  
    50. // Attaching a click event to the current marker
    51. google.maps.event.addListener(marker, "click", function (e) {
    52. infoWindow.setContent(data.description);
    53. infowindow.open(map, marker);
    54. });
    55.  
    56.  
    57. //google.maps.event.addListener(marker, "mouseover", function (e) {
    58. // infoWindow.setContent(data.description);
    59. // infowindow.open(map, marker);
    60. //});
    61.  
    62.  
    63.  
    64. })(marker, data);
    65.  
    66.  
    67. }
    68. // End of newly added code block
    69. }

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: