Integrating database with google static map markers (overlays)
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开发者_JS百科 map.
Any tutorial or help will be highly appreciated
Edition of the post #1 by M'vy
Ok. I think I got the point. So I edit the answer to use the code snippet.
The following code has to be used for ONE mapId
int mapID = Convert.ToInt16(hdnMapID.Value);
/* I suppose this executes the following SQL query :
* SELECT lat, lng FROM Table WHERE mapID = :mapID;
*/
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";
/* This is the basic link, with no markers */
string URLStart = "http://maps.google.com/maps/api/staticmap?center=" +
center + "&zoom=" + zoom + " &size=" + size + "&maptype=" + maptype + "&sensor=true";
string markersStr = "";
/* Each record we will read correspond to one point on the map:
* NB you don't need the markerID
* We add each point long and lat to the string */
while (dr.Read()) {
markersStr += "&markers=color:blue|label:S|" + dr["lat"] + ", " + dr["lng"] + ;
}
map2.ImageUrl = URLStart + markersStr;
dr.Dispose();
//Then display the map with the URL that has all the point for mapId
The markerId
is of no use. You can easily compute the value by using
SELECT COUNT(*) FROM Table WHERE mapID = 581;
First Post
Hello Muhammad,
You can find your answer in the Google Map Static API here
For multiple markers, you just have to repeat the markers parameter in the URL.
You can choose a different color, name etc. Just append a new &markers=<blah blah>
M'vy
To create the static map URL you can use this open source project - http://code.google.com/p/google-maps/
精彩评论