updated google map sample part 2

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PushToGoogle.aspx.cs" Inherits="PushToGoogle" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>No name</title>
      
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAA0fjp2tHrrQJwoaRp8r_sYxR9fR65Vek3QPwU0sVxyfrqv-3SrxSOi2QPW6Z4SZY2sm8l2ZDVezrplA" type="text/javascript"></script> 
      
<script type="text/javascript">
var geocoder;
var request=false;
var addressList = new Array();
var mlsList = new Array();
var zipcodeList = new Array();
<%=address.ToString()%>
<%=mls.ToString()%>
<%=zipcode.ToString()%>
var totalRecords=mlsList.length;
var currentRecord=0;
try
{
 request 
= new XMLHttpRequest();//Firefox
}

catch(trymicrosoft)
{
 
try 
 
{
    request 
= new ActiveXObject("Msxml2.XMLHTTP.5.0");//New IE
 }
 
 
catch(othermicrosoft)
 
{
    
try 
    
{
          request 
= new ActiveXObject("Microsoft.XMLHTTP");//Old IE
    }
 
    
catch(failed)
    
{
          request 
= false;//Unknown browser
    }

 }

}

if (GBrowserIsCompatible()) 
{
    geocoder 
= new GClientGeocoder();
}

function saveResult(mls,latitude,longitude)
{
   
var url=escape("PullFromGoogle.aspx")+"?random=" + Math.random();
   request.open(
"Post",url,true);
   request.setRequestHeader(
'Content-Type''application/x-www-form-urlencoded; charset=utf-8');
   request.send(
"mls="+escape(mls)+"&latitude="+escape(latitude)+"&longitude="+escape(longitude));
}

function buildRequests()
{
    
if(currentRecord<totalRecords)
    
{
        sendRequestByAddress(addressList[currentRecord],mlsList[currentRecord],zipcodeList[currentRecord]);
        currentRecord
++;
        setTimeout(
"buildRequests()",2000);//2 seconds
    }

}

function sendRequestByAddress(address,mls,zipcode)

   
if(geocoder)
   
{
      geocoder.getLatLng
      (
        address,
        
function(point)
        
{
          
if(point)
          
{
            saveResult(mls,point.lat(),point.lng());
          }

          
else
          
{
            saveResult(mls,
"error","error");
            sendRequestByZipcode(zipcode,mls);
          }

        }

      );
   }

}

function sendRequestByZipcode(zipcode,mls)

   
if(geocoder)
   
{
      geocoder.getLatLng
      (
        zipcode,
        
function(point)
        
{
          
if(point)
          
{
            saveResult(mls,point.lat(),point.lng());
          }

          
else
          
{
            saveResult(mls,
null,null);
          }

        }

      );
   }

}

      
</script>
</head>
<body onload="buildRequests();" onunload="GUnload();">
    
<form id="form1" runat="server">
   
<div>
    
    
</div>
    
</form>
</body>
</html>

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;

public partial class PushToGoogle : System.Web.UI.Page
{
    
private DataTable dt;
    
public StringBuilder address;
    
public StringBuilder mls;
    
public StringBuilder zipcode;

    
protected void Page_Load(object sender, EventArgs e)
    
{
        
this.dt = fillTable();
        address 
= new StringBuilder();
        mls 
= new StringBuilder();
        zipcode 
= new StringBuilder();
        
for (int i = 0; i < dt.Rows.Count; i++)
        
{
            address.AppendLine(
"addressList[" + i + "]=\"" + dt.Rows[i][0].ToString().Trim() + "," + dt.Rows[i][3].ToString().Trim() + ",alberta,canada\";");
            mls.AppendLine(
"mlsList[" + i + "]=\"" + dt.Rows[i][1].ToString().Trim() + "\";");
            zipcode.AppendLine(
"zipcodeList[" + i + "]=\"" + dt.Rows[i][2].ToString().Trim() + ",alberta,canada\";");
        }

    }


    
private DataTable fillTable()
    
{
        
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionInfo"].ConnectionString))
        
{
            
using (SqlCommand comm = new SqlCommand("select distinct address,mlsnumber,zipcode,areadesc from v_res_idx_testing", conn))
            
{
                
using (SqlDataAdapter da = new SqlDataAdapter(comm))
                
{
                    DataTable dt 
= new DataTable();
                    da.Fill(dt);
                    
return dt;
                }

            }

        }

    }

}



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PushNearBySearchToGoogle.aspx.cs" Inherits="PushNearBySearchToGoogle" %>

<html xmlns="http://www.w3.org/1999/xhtml">
    
<head>
        
<title>Need a title?</title>
        
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAA0fjp2tHrrQJwoaRp8r_sYxR9fR65Vek3QPwU0sVxyfrqv-3SrxSOi2QPW6Z4SZY2sm8l2ZDVezrplA" type="text/javascript"></script>
        
<script src="http://www.google.com/uds/api?file=uds.js&amp;v=1.0&amp;key=ABQIAAAA0fjp2tHrrQJwoaRp8r_sYxR9fR65Vek3QPwU0sVxyfrqv-3SrxSOi2QPW6Z4SZY2sm8l2ZDVezrplA" type="text/javascript"></script>
        
<script type="text/javascript">
            
var request=false;
            
var gLocalSearch;
            
var addressList = new Array();
            
var zipcodeList = new Array();
            
var categoryList = new Array();
            
var categoryIDList = new Array();
            
<%=addressList.ToString()%>
            
<%=zipcodeList.ToString()%>
            
<%=categoryList.ToString()%>
            
<%=categoryIDList.ToString()%>
            
var totalRecords = addressList.length;
            
var totalCategories = categoryList.length;
            
var currentRecordIndex = 0;
            
var currentCategoryIndex = 0;
            
var triedAgain;
            
try
            
{
             request 
= new XMLHttpRequest();//Firefox
            }

            
catch(trymicrosoft)
            
{
             
try 
             
{
                request 
= new ActiveXObject("Msxml2.XMLHTTP.5.0");//New IE
             }
 
             
catch(othermicrosoft)
             
{
                
try 
                
{
                      request 
= new ActiveXObject("Microsoft.XMLHTTP");//Old IE
                }
 
                
catch(failed)
                
{
                      request 
= false;//Unknown browser
                }

             }

            }

            
function load() 
            
{
                gLocalSearch 
= new GlocalSearch();
                gLocalSearch.setResultSetSize(GSearch.LARGE_RESULTSET);
                gLocalSearch.setSearchCompleteCallback(
null, dealResults);
                doSearch();
            }

            
function dealResults() 
            
{
                
if(!gLocalSearch.results)
                

                    
return;
                }

                
if(gLocalSearch.results.length==0&&(!triedAgain))
                
{
                    doBackUpSearch();
                    
return;
                }

                
for(var i = 0; i < gLocalSearch.results.length; i++
                
{
                    
var result = gLocalSearch.results[i];
                    
if(result.titleNoFormatting)
                    
{
                        
var title = result.titleNoFormatting;
                    }

                    
else
                    
{
                        
var title = null;
                    }

                    
if(result.city)
                    
{
                        
var city = result.city;
                    }

                    
else
                    
{
                        
var city = null;
                    }

                    
if(result.region)
                    
{
                        
var region = result.region;
                    }

                    
else
                    
{
                        
var region = null;
                    }

                    
if(result.country)
                    
{
                        
var country = result.country;
                    }

                    
else
                    
{
                        
var country = null;
                    }

                    
try
                    
{
                        
var phone = result.phoneNumbers[0].number;
                    }

                    
catch(err)
                    
{
                        
var phone = null;
                    }

                    
var longitude = result.lng;
                    
var latitude = result.lat;
                    saveResult(title, city, region, country, phone, longitude, latitude,categoryIDList[currentCategoryIndex]);
                }

            }

            
function doBackUpSearch()
            
{
                triedAgain
=true;
                gLocalSearch.setCenterPoint(zipcodeList[currentRecordIndex]);
                gLocalSearch.execute(categoryList[currentCategoryIndex]);
            }

            
function doSearch()
            
{
                
if(currentCategoryIndex<totalCategories)
                
{
                    
if(currentRecordIndex<totalRecords)
                    
{
                        triedAgain
=false;
                        gLocalSearch.setCenterPoint(addressList[currentRecordIndex]);
                        gLocalSearch.execute(categoryList[currentCategoryIndex]);
                        currentRecordIndex
++;
                        setTimeout(
"doSearch()",2000);//2 seconds
                    }

                    
else
                    
{
                        currentRecordIndex 
= 0
                        currentCategoryIndex
++;
                        setTimeout(
"doSearch()",2000);//2 seconds
                    }

                }

            }

            
function saveResult(title, city, region, country, phone, longitude, latitude, categoryID)
            
{
               
var url=escape("PullNearBySearchFromGoogle.aspx")+"?random=" + Math.random();
               request.open(
"Post",url,true);
               request.setRequestHeader(
'Content-Type''application/x-www-form-urlencoded; charset=utf-8');
               request.send(
"title="+escape(title)+"&city="+escape(city)+"&=region"+escape(region)+"&country="+escape(country)+"&phone="+escape(phone)+"&longitude="+escape(longitude)+"&latitude="+escape(latitude)+"&categoryID="+escape(categoryID));
            }

            GSearch.setOnLoadCallback(load);
        
</script>
    
</head>
    
<body onunload="GUnload()">
    
</body>
</html>


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Data.SqlClient;

public partial class PushNearBySearchToGoogle : System.Web.UI.Page
{
    
public StringBuilder addressList;
    
public StringBuilder zipcodeList;
    
public StringBuilder categoryList;
    
public StringBuilder categoryIDList;

    
protected void Page_Load(object sender, EventArgs e)
    
{
        addressList 
= new StringBuilder();
        zipcodeList 
= new StringBuilder();
        categoryList 
= new StringBuilder();
        categoryIDList 
= new StringBuilder();
        DataTable addressAndZipcode 
= FillAddressAndZipcodeTable();
        DataTable category 
= FillCategoryTable();
        
for (int i = 0; i < addressAndZipcode.Rows.Count; i++)
        
{
            addressList.AppendLine(
"addressList[" + i + "]=\"" + addressAndZipcode.Rows[i]["address"].ToString().Trim() + "," + addressAndZipcode.Rows[i]["areadesc"].ToString().Trim() + ",alberta,canada\";");
            zipcodeList.AppendLine(
"zipcodeList[" + i + "]=\"" + addressAndZipcode.Rows[i]["zipcode"].ToString().Trim() + "," + addressAndZipcode.Rows[i]["areadesc"].ToString().Trim() + ",alberta,canada\";");
        }

        
for (int i = 0; i < category.Rows.Count; i++)
        
{
            categoryList.AppendLine(
"categoryList[" + i + "]=\"" + category.Rows[i]["description"].ToString().Trim() + "\";");
            categoryIDList.AppendLine(
"categoryIDList[" + i + "]=\"" + category.Rows[i]["subcategoryID"].ToString().Trim() + "\";");
        }

    }

    
private DataTable FillAddressAndZipcodeTable()
    
{
        
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionInfo"].ConnectionString))
        
{
            
using (SqlCommand comm = new SqlCommand("select distinct address,zipcode,areadesc from v_res_idx_testing", conn))
            
{
                
using (SqlDataAdapter da = new SqlDataAdapter(comm))
                
{
                    DataTable dt 
= new DataTable();
                    da.Fill(dt);
                    
return dt;
                }

            }

        }

    }

    
private DataTable FillCategoryTable()
    
{
        
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionInfo"].ConnectionString))
        
{
            
using (SqlCommand comm = new SqlCommand("select subcategoryID,description from subcategory order by subcategoryid desc", conn))
            
{
                
using (SqlDataAdapter da = new SqlDataAdapter(comm))
                
{
                    DataTable dt 
= new DataTable();
                    da.Fill(dt);
                    
return dt;
                }

            }

        }

    }

}

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;

public partial class PullNearBySearchFromGoogle : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    
{
        
try
        
{
            
//the title can not be null, if it is ,then throw the error
            string title = Microsoft.JScript.GlobalObject.unescape(this.Request.Form["title"].ToString());
            
string city;
            
try
            
{
                city 
= this.Request.Form["city"].ToString();
            }

            
catch
            
{
                city 
= string.Empty;
            }

            
string region;
            
try
            
{
                region 
= this.Request.Form["region"].ToString();
            }

            
catch
            
{
                region 
= string.Empty;
            }

            
string country;
            
try
            
{
                country 
= this.Request.Form["country"].ToString();
            }

            
catch
            
{
                country 
= string.Empty;
            }

            
string phone;
            
try
            
{
                phone 
= this.Request.Form["phone"].ToString();
            }

            
catch
            
{
                phone 
= string.Empty;
            }

            
string longitude;
            
try
            
{
                longitude 
= this.Request.Form["longitude"].ToString();
            }

            
catch
            
{
                longitude 
= string.Empty;
            }

            
string latitude;
            
try
            
{
                latitude 
= this.Request.Form["latitude"].ToString();
            }

            
catch
            
{
                latitude 
= string.Empty;
            }

            
//this one must be ok in order to do the next, if error happens, throw it and not save it to database
            int categoryID = Convert.ToInt32(this.Request.Form["categoryID"]);
            
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionInfo"].ConnectionString))
            
{
                conn.Open();
                
using (SqlCommand comm = new SqlCommand("SaveLocationSearch", conn))
                
{
                    comm.CommandType 
= CommandType.StoredProcedure;
                    comm.Parameters.AddWithValue(
"@title", title);
                    comm.Parameters.AddWithValue(
"@city", city);
                    comm.Parameters.AddWithValue(
"@region", region);
                    comm.Parameters.AddWithValue(
"@country", country);
                    comm.Parameters.AddWithValue(
"@longitude", longitude);
                    comm.Parameters.AddWithValue(
"@latitude", latitude);
                    comm.Parameters.AddWithValue(
"@subcategoryid", categoryID);
                    comm.Parameters.AddWithValue(
"@phone", phone);
                    comm.ExecuteNonQuery();
                }

            }

        }

        
catch
        
{
        }

    }

    
private void WriteFile(string filePath, string content)
    
{
        
if (!Directory.Exists(Path.GetDirectoryName(filePath)))
        
{
            Directory.CreateDirectory(Path.GetDirectoryName(filePath));
        }

        
using (StreamWriter sw = new StreamWriter(filePath))
        
{
            sw.Write(content);
        }

    }

}

posted @ 2008-02-21 06:54  N/A2011  阅读(290)  评论(0编辑  收藏  举报