protected void Page_Load(object sender, EventArgs e)
{
string st = MappedApplicationPath + "address.xls"; //virtual location of the excel document
String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + st + ";" +
"Extended Properties=Excel 8.0;"; //set the connection string
OleDbConnection objConn = null; ;
try
{
//open connection and execute query
objConn = new OleDbConnection(sConnectionString);
objConn.Open();
OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM [Sheet1$]", objConn);
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
objAdapter1.SelectCommand = objCmdSelect;
DataSet objDataset1 = new DataSet();
objAdapter1.Fill(objDataset1);
ArrayList arrAdd = new ArrayList();
//read each entry in excel's document first column
foreach (DataTable table in objDataset1.Tables)
foreach (DataRow row in table.Rows)
{
string s = "";
foreach (DataColumn col in table.Columns)
{
s = s + " " + row[col].ToString();
}
arrAdd.Add(s); //add each address to an ArrayList
}
ViewState["edward"] = arrAdd; //add the ArrayList in a ViewState object
}
catch (Exception ex)
{
string s = ex.ToString();
}
finally
{
objConn.Close();
}
}
//get the virtual location
protected string MappedApplicationPath
{
get
{
try
{
string APP_PATH = System.Web.HttpContext.Current.Request.ApplicationPath.ToLower();
if (APP_PATH == "/") //a site
APP_PATH = "/";
else if (!APP_PATH.EndsWith(@"/")) //a virtual
APP_PATH += @"/";
string it = System.Web.HttpContext.Current.Server.MapPath(APP_PATH);
if (!it.EndsWith(@"\"))
it += @"\";
return it;
}
catch (Exception nre)
{
return null;
}
} //end get
} //end mapped
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="getCoordinate.aspx.cs" Inherits="getCoordinate" %>Note:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps API Example - Geocoding API</title>
<script src="http://maps.google.com/maps?file=api&v=2.x&key=googlekeyapi" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
var map = null;
var geocoder = null;
function load() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(37.4419, -122.1419), 13); //set the center map to "1600 Amphitheatre Pky, Mountain View, CA"
geocoder = new GClientGeocoder(); //create a new Geocoder object
}
}
<% ArrayList arrAdd = (ArrayList)ViewState["edward"]; %>
function showAddress() {
if (geocoder) {
var address = null;
var d = open('', ''); //open a blank document
<% for(int i = 0; i < arrAdd.Count; i++) { %>
address = '<% Response.Write(arrAdd[i].ToString()); %>';
geocoder.getLatLng(
address,
function(point) { //display the string address and its corresponding longtitude, latitude
d.document.write('<% Response.Write(arrAdd[i].ToString()); %> :sachiko: ' + point + '<br />');
} // sample printed data: 1 Star Drive Laguna Niguel :sachiko: (33.541886, -117.676792)
);
<% } %>
}
}
//]]>
</script>
</head>
<body onload="load()" onunload="GUnload()">
<form action="#" onsubmit="showAddress(); return false">
<p>
<input type="text" size="60" name="address" value="1600 Amphitheatre Pky, Mountain View, CA" />
<input type="submit" value="Go!" />
</p>
<div id="map" ></div>
</form>
</body>
</html>
1 Star Drive Laguna Niguel
1011 Brioso Drive, Suite 108 Costa Mesa
10605 Bechler River Ave Fountain Valley
10605 Bechler River Ave. Fountain Valley
10900 Firestone Blvd Norwalk
11800 Woodruff Ave. Downey
1201 Normandy Pl Santa Ana
1227 S LA BREA AVE INGLEWOOD
1290 Knollwood Circle Anaheim