locked
integrating Data base with Google Static Map url RRS feed

  • Question

  • User1073523950 posted

    Hi, 

    I cant find the way to create overlays on the static google map through database. I can acheive the a single marker(location) easily. below is the code:

     int mapID = Convert.ToInt16(hdnMapID.Value);
            SqlDataReader dr =  Maps.GetMapPointsByMapIDUserID(mapID, userID);
    
    
           string latitude = "53.615143";
           string longitude = "-1.711380";
            string center = "" + latitude + "," + longitude + "";
            string zoom = "20";
            string size = "512x512";
            string maptype = "roadmap";
    
            while (dr.Read())
            {
          
    
                    map2.ImageUrl = "http://maps.google.com/maps/api/staticmap?center=" + center + "&zoom=" + zoom + " &size=" + size + "&maptype=" + maptype + "&markers=color:blue|label:S|" + dr["lat"] + ", " + dr["lng"] + "&sensor=true";
                }
    
             
    
                cnt++;
            }
            dr.Dispose();

    In the above url, its easy to pass marker value (color:blue|label:S|"+ dr["lat"] + "," + dr["lng"] +) for a single location, but in my project I have got multiple locations and I cant find a way to create different urls for multiple locations for instance if there are two locations there will be 2 markers in the above url, how can I create programatically google static url depending on the numbers of markers(overlays) present in the map.

     

    Any tutorial or help will be highly appreciated

    Monday, February 28, 2011 11:16 AM

Answers

  • User1073523950 posted

    Finally I have sorted out the issue : below is the code if any one wants to call the marker location through database , also changing the marker color, Here I have used only 2 colors , green as a source while all other location will be displayed as red.

     void DrawStaticMap()
        {
            StringBuilder sb = new StringBuilder();
         
            int mapID = Convert.ToInt16(hdnMapID.Value);
            SqlDataReader dr =  Maps.GetMapPointsByMapIDUserID(mapID, userID);
    
    
            string latitude = "53.615143";
           string longitude = "-1.711380";
            string center = "" + latitude + "," + longitude + "";
           // string zoom = "20";
            string size = "512x512";
            string maptype = "roadmap";
            string URLStart = "http://maps.google.com/maps/api/staticmap?size=" + size + "&maptype=" + maptype + "&sensor=true";
            string markersStr = "";
            List<string> colors = new List<string>();
            colors.Add("green");
          //  colors.Add("blue");
            colors.Add("red");
            int i = 0;
            while (dr.Read())
            {
           
               // Here you can use for loop to change the index for color
                markersStr += "&markers=color:" + colors[i] + "|" + dr["lat"] + ", " + dr["lng"] +"" ;
                colors.Remove("green");
              
              
            }
            map2.ImageUrl = URLStart + markersStr;
            dr.Dispose();

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 1, 2011 9:13 AM

All replies

  • User1073523950 posted

    Working on it with the assistance of a guy at stackoverflow.. let see how it goes will post it if I manage to solve it .

     

    Thnx

    Monday, February 28, 2011 5:18 PM
  • User1073523950 posted

    Finally I have sorted out the issue : below is the code if any one wants to call the marker location through database , also changing the marker color, Here I have used only 2 colors , green as a source while all other location will be displayed as red.

     void DrawStaticMap()
        {
            StringBuilder sb = new StringBuilder();
         
            int mapID = Convert.ToInt16(hdnMapID.Value);
            SqlDataReader dr =  Maps.GetMapPointsByMapIDUserID(mapID, userID);
    
    
            string latitude = "53.615143";
           string longitude = "-1.711380";
            string center = "" + latitude + "," + longitude + "";
           // string zoom = "20";
            string size = "512x512";
            string maptype = "roadmap";
            string URLStart = "http://maps.google.com/maps/api/staticmap?size=" + size + "&maptype=" + maptype + "&sensor=true";
            string markersStr = "";
            List<string> colors = new List<string>();
            colors.Add("green");
          //  colors.Add("blue");
            colors.Add("red");
            int i = 0;
            while (dr.Read())
            {
           
               // Here you can use for loop to change the index for color
                markersStr += "&markers=color:" + colors[i] + "|" + dr["lat"] + ", " + dr["lng"] +"" ;
                colors.Remove("green");
              
              
            }
            map2.ImageUrl = URLStart + markersStr;
            dr.Dispose();

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 1, 2011 9:13 AM