Tuesday, May 09, 2006

Some Code Differences Between WebDemo and KD Test Google Map Site

In our production environment, I created a table in our database to store geocodes for each country capitals rather than constructing xml data file on the fly. The system will first go to our database table and check if there exists a record for the country capital. If so, merge it with counting records; otherwise, it jumps out onto the internet and retrieves the geocode from Yahoo geocoding service, finishes merging process and then insert back to database table.

Here is complete version of the codes:

private void MergeDataAll(XmlTextWriter objX, SqlDataReader dr)
{
MapDataAccess da = new MapDataAccess(Global.CONNSTRING);
SqlDataReader drG;

GoogleAddress ga = new GoogleAddress();
MapData md = new MapData();

string strC = "";
while(dr.Read())
{
strC = dr["ADR1_COUNTRY"].ToString();
drG = da.GetCCGeocode(strC,MapData.Capital(strC).Trim());

drG.Read();
if ((drG.HasRows)&&(drG["Lat"].ToString() != "")&&(drG["Lng"].ToString()!= ""))
{
objX.WriteStartElement("marker");
objX.WriteAttributeString("lat", drG["Lat"].ToString());
objX.WriteAttributeString("lng",drG["Lng"].ToString());
objX.WriteAttributeString("country",strC);
objX.WriteAttributeString("title", strC);
objX.WriteAttributeString("message", dr["CountryTotal"].ToString());
objX.WriteEndElement();
}
else
{
md.SetGeocodesEach(strC, MapData.Capital(strC).Trim());
md.GetGeocodes(ga);
if ((ga.Latitude != 0) && (ga.Longitude != 0))
{
objX.WriteStartElement("marker");
objX.WriteAttributeString("lat", ga.Latitude.ToString());
objX.WriteAttributeString("lng",ga.Longitude.ToString());
objX.WriteAttributeString("country",strC);
objX.WriteAttributeString("title", strC);
objX.WriteAttributeString("message", dr["CountryTotal"].ToString());
objX.WriteEndElement();
//Insert lat and lng into database.
da.closeConn();
if (MapData.Capital(strC).Trim() != "")
da.InsertCCGeocode(strC,MapData.Capital(strC).Trim(),ga.Latitude.ToString(),ga.Longitude.ToString());
}
}
drG.Close();
}
}

Our table is called CCGeocode and there are only four fields: Country, Capital, Lat and Lng. Here is the code snippet that makes use of Microsoft applicationblocks to insert:

public bool InsertCCGeocode(string strCountry, string strCity, string strLat, string strLng)
{
string queryString="Insert Into CCGeocode";
queryString += " (Country, Capital, Lat, Lng)";
queryString += " values ('"+strCountry+"', '"+strCity+"', '" +strLat+"', '"+strLng+"')";
bool success=false;
SqlCommand myCommand=new SqlCommand(queryString, conn);
conn.Open();
int rows = myCommand.ExecuteNonQuery();
if (rows > 0)
{
success=true;
}
conn.Close();
return success;
}

To download a WebDemo project, please visit:
http://www.codeproject.com/
To see an active Google Map:
http://test.kd.iu.edu/GoogleMap/AlumStatesMap.aspx

18 Comments:

Blogger Paul Adams said...

Hi there Blogger, a real useful blog.Keep with the good work.
If you have a moment, please visit my yahoo music lyric site.
I send you warm regards and wishes of continued success.

1:38 AM  
Blogger PersonalPhoneChat-Tjt said...

This is good stuff here. You can contribute articles and info at my site about phone sex.

12:14 PM  
Blogger ryhr91 said...

Hey, you have a great blog here! I'm definitely going to bookmark you!

I have a internet marketing search engine site/blog. It pretty much covers ##KEYWORD## related stuff.

6:01 AM  
Blogger Jaffe said...

Hey, while searching for widgets for my blog, I stumbled upon www.widgetmate.com and wow! I found what I wanted. A cool news widget. My blog is now showing latest news with title, description and images. Took just few minutes to add. Awesome!

12:56 PM  
Blogger adam said...

Hello I just entered before I have to leave to the airport, it's been very nice to meet you, if you want here is the site I told you about where I type some stuff and make good money (I work from home): here it is

9:09 PM  
Blogger adam said...

Hello I just entered before I have to leave to the airport, it's been very nice to meet you, if you want here is the site I told you about where I type some stuff and make good money (I work from home): here it is

9:31 PM  
Blogger bernard n. shull said...

i did a little research after you told me about your "thing", and if you want a way to make more money using your your blog you can enter this site: link. bye.

3:08 AM  
Blogger Mazhar Hussain Shah said...

Hi,

Thanks for sharing the great list of the many new version of the quote,In my point of view it is a very good way of introduce yourself.And it is also very important for the users that in this way they can take a useful information of web designing.
.

9:58 PM  
Blogger sanga said...

Thanks for sharing the informative information keep on updating the latest information. This is a good stuff. This site is offering the Filmview Services: Video Production Sydney, creators of professional video productions, motion graphics and video editing that engages, entertains and intrigues your audience. Specialists in film, broadcast & event content for screens click here Professional Video Production

9:57 AM  
Blogger willam said...

Web Development bahrain is a team of qualified and experienced Web Developers who are capable of handling projects of any size and can deliver the completed project on time.

3:15 AM  
Blogger Shiv said...

thanks for the post though i have found everything what i wanted to know post is really informative and nice , because now i got to know what SSL certificates are really used for.Website Hosting

3:31 AM  
Blogger anusuyaw3solutions said...

I have read this post. This post is a nice one that information are useful to me..that am doing web designing company chennai india , website designing company chennai india and web development company chennai india. That I will inform about your post to my friends and all the best for your future posts..

11:51 PM  
Blogger vasanthi said...

I have read this post. collection of post is a nice one ..that am doing website designing company chennai india and website development company chennai india. That I will inform about your post to my friends and all the best for your future posts..

10:48 PM  
Blogger kk said...

Multimedia Flash website design dallas ensures maximum penetration with higher acceptance levels. We bring together the best in multimedia technologies so that you stay a creative step ahead of your competition. Flash website design dallas Design Multimedia Presentation, CD Presenataion, Academic Software, Online Educational Software, Web Design and hosting of educational software, Home Schooling Software and Commercial Software.Now our service is in online 24 hour and 7 day's on a week for you please don't forget to bookmark this http://www.flashwebz.com/.

11:21 AM  
Blogger Alex Walker said...

Hey,

Am grateful to you for this good content.I am reading your article and its very nice, useful & helpful for those guys who wanna know about the same. Thanks for sharing information about Website Hosting & Design

Thanks
Alex Walker

7:21 PM  
Blogger Cloud Hosting said...

This comment has been removed by the author.

12:27 AM  
Blogger gexhouse2 said...

Gexhost provides reliable, cheap, best web hosting solution in Pakistan. You can get domain registration,
web hosting services with uptime guarantee. We are top hosting provider.

Cheap web hosting pakistan
Php hosting pakintan

3:49 AM  
Blogger aparna john said...

Hi,Every website designer must have a strong sense of aesthetics and yes, the design schools indeed provide high level of artistic educational environment. In this time of business globalization it is indeed heartening to reach the website designer who offer end to end customer friendly site at affordable rates in Web Design Cochin. In case of any doubts it is best to go for the no obligation quotes.Thanks.....

1:45 AM  

Post a Comment

<< Home