很多人裝好Google Earth應該都會先手賤的輸入「Taipei」等中文地名查詢,記得以前還查不到任何地點咧,現在也好不到哪裡去,除了英文地名沒有人記得住之外,照表 輸入還是有很多查不到的。我們只是先熟悉一下搜尋框的使用方法,稍後再搭配其他地圖服務一起加強搜尋。
輸入關鍵字之後,地圖畫面會以動畫飛向定點,最後畫面的中央會定位在找到的地標,搜尋框下也會出現並勾選符合的項目。地圖上也會有相同的瞄準鏡圖示,下方顯示的經緯度也會即時跟著變動。
由於搜尋結果在正中央,可以縮放地圖以便觀察周遭的影像,中心點是不會變的。 除了輸入關鍵字,Google Earth也可以直接以經緯度查詢地圖,經緯度有幾種常見的標示法(詳見「關鍵字」的解釋),在搜尋框裡頭也可以通用,底下我們先把地圖上標示的經緯度變更為十進位,這樣就可以和後面一些網路服務的標示單位統一了。
------------------------------------------------------------------------
@關鍵字:經緯度緯 度(Latitude),經度(Longitude)是用來標訂地球上座標的假想線。經緯度牽涉到的領域及知識很廣泛,我們僅就所知的部份概略解說。假設 從水平的赤道,及垂直的本初子午線將地球一分為四,赤道以上為北緯線,下方是南緯,分別是從0度到90度;
同樣的,本初子午線右方是東經,左邊則有西經 線,單位是0到180度。 經緯度有幾種常見的標示方法,例如25。1’12.00”N代表北緯25度1分12秒,依此類推,分和秒是比度更小的角度單位,為60進 位,而秒數的小數點則是用來呈現更精細的刻度。在本篇文章套用的軟體,大多是換算成十進位輸入,東、西經,北、南緯則是用正、負符號來區別。
目前 Google Earth和各種GPS接收器都使用最新的WGS 84座標系統,除了傳統的假想線分割,也會根據實際情況修正座標,比方經度的起點並不在傳統本初子午線的格林威治。補充說明,台灣地圖是採用另一種「二分 帶」座標系統,兩者之間必須透過複雜的公式轉換。
------------------------------------------------------------------------
參考別人上傳的地標 Google Earth對中文世界的支援實在是很匱乏,還好在laXXXXXyers面板底下可以打開「Google Earth Community」顯示層,裡頭有不少熱心網友替台灣各個地方加入的地標。其他面板的使用方式也大同小異,不同性質的地標在地圖裡會顯示成不同的圖示, 甚至有地震帶、火山等等觀測資訊,不過一般人比較實用的還是Community的「i」圖示,在樹狀目錄下的「Community Showcase」也有其他不同的地標類型圖示。 有了現成的地標,就比較容易辨認、搜尋鄰近的地圖了。
不過解析度拉遠一點,一堆「i」圖示擠在一起也蠻噁心的,除了取消勾選資料夾底下的細項之外,也可以 把比較實用的地標直接保存到個人資料夾「My Places」,這有點像是書籤的作用,也可以區分成不同資料夾分類,後面我們自行標示的景點同樣也可以保存在這裡。隨著勾選、取消勾選就可以切換顯示一 個或一組不同的地標。
搭配UrMap查詢座標 UrMap:http://www.urmap.com/ Greasemonkey:http://greasemonkey.mozdev.org/ UrMap Plus:http://flickr.tw/2005/12/_urmap_geotagged_flickr_photos.html
比起來另一套國人出品的UrMap,只有台灣地區的地圖,但是中文的搜尋效率和結果當然就好太多了。只是UrMap和Google Maps一樣,在網頁上直接互動執行,而不像Google Earth是安裝到電腦的軟體,畫面自然遜色了些。由於我們的計畫是替數位照片加入座標資訊,然而UrMap的搜尋結果卻是沒有座標的,比較笨的方法就是 兩個軟體都打開,然後把UrMap的顯示模式切換到「衛星影像」或「衛星地圖」,用UrMap的搜尋結果比對到Google Earth裡的經緯度座標。
還好有另一位強者網友製作了「UrMap Plus」User javascXXXXXript(UserJS),簡單的解釋一下,UserJS是瀏覽器外掛的小程式,能夠強制修改網頁的呈現方式和功能。我們是以Firefox 實作,必須先安裝Greasmonkey擴充套件做為UserJS執行的平台,再裝上UrMap Plus,再次連上UrMap會發現加入了經緯度顯示的功能(以地圖中心點為準),還多了「Google Earth」、「Google Maps」的按鈕,按一下就可以把兩種地圖疊上去,實在是太強了。
分享 ASP,ASP.NET,VB,C#,程式開發,網站設計,部落格,微網誌,網路行銷,facebook 行銷,噗浪行銷,社群行銷,電腦硬體軟體,網路賺錢等資訊內容。『噗落格』裡的文章大多是從各網站摘錄(轉貼)下來的,僅提供研究及筆記之用途,如有侵權請留言告知!一開始不打算賺錢,一個不可能中的可能
2009年5月18日 星期一
如何將經緯度利用Google Map API顯示 C# VS2005 Sample Code
當我們知道住址時,也可以這樣套用
http://maps.google.com/maps?q=台北縣中和市莒光路
當我們知道經緯度後,只要將數據套到以下網址即可.
http://maps.google.com/maps?q=25.048346%2c121.516396
在參數q=後面,就可以加上經緯度了.
25.048346是Latitude緯度
%2c是空格
121.516396就是Longitude經度了.

而另一種做法就比這個複雜一點,要使用Google API來做,首先,要使用google API就必需要有google的帳號,沒帳號是無法申請的,當有google的帳號後,就可以到http://code.google.com/apis/maps/signup.html開始申請了.

最下方My web site URL就輸入各位的URL囉,如果輸入的與執行google map api的URL不同,那就無法執行了.所以這個URL務必輸入正確, 輸入正確的URL並將上方的CheckBox打勾後,就可以按Generate API Key了,如果已經登入GOOGLE的,就不會再跳登入畫面,之後就會跳到另一個畫面,上面就有Key及Example Code了,當有了這些,就可以開始自己寫Code了.
基本上,因為主要是Demo用的,所以設計介面很簡單.
上面就一個DropDownList,因為先前的範例資料的關係,先手動在ITEM上加上1跟2.
而下方的地圖,就跟申請API時的Example Code一樣. 原始碼如下 :
< %@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
< !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>GPS 位置地圖< /title>
< script src="http://maps.google.com/maps?file=api&v=2&key=輸入你的Key"
type="text/javascript">< /script>
< script src="http://www.google.com/uds/api?file=uds.js&v=1.0&key=輸入你的Key"
type="text/javascript">< /script>
< script src="http://www.google.com/uds/solutions/localsearch/gmlocalsearch.js" type="text/javascript">< /script>
< style type="text/css"> @import url("http://www.google.com/uds/css/gsearch.css");
@import url("http://www.google.com/uds/solutions/localsearch/gmlocalsearch.css");
< /style>
< script type="text/javascript">
//< ![CDATA[
function load(x,y,LocationName) {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
var point = new GLatLng(x,y);
map.setCenter(point, 16);
map.addOverlay(new GMarker(point));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GScaleControl());
var lsc = new google.maps.LocalSearch();
map.addControl(new google.maps.LocalSearch() , new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,20)));
map.openInfoWindowHtml (map.getCenter(), LocationName);
}
}
//]]>
< /script>
< /head>
< body id="MainBody" runat="server">
< form id="form1" runat="server">
< div>
< asp:DropDownList ID="ddl_Location" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddl_Location_SelectedIndexChanged"
Width="500px">
< asp:ListItem>1< /asp:ListItem>
< asp:ListItem Value="2">2< /asp:ListItem>
< /asp:DropDownList>< br />
< br />
< div id="map" style="width: 500px; height: 400px">
< /div>
< /div>
< /form>
< /body>
< /html>
只要將"輸入你的Key"的地方置換為你在Google MAP API申請到的Key即可.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.QueryString.HasKeys())
{
string longitude = Request.QueryString.Get("lon");
string latitude = Request.QueryString.Get("lat");
string LN = Request.QueryString.Get(Server.UrlDecode("LN"));
this.MainBody.Attributes.Add("onload", "load(" + longitude + "," + latitude + ",'" + LN + "')");
}
else
{
DataTable dt = GetLocation(ddl_Location.SelectedValue);
if (dt.Rows.Count > 0)
{
DataRow dr = dt.Rows[0];
this.MainBody.Attributes.Add("onload", "load(" + dr["Latitude"].ToString() + "," + dr["Longitude"].ToString() + ",'" + dr["updtime"].ToString() + "')");
}
}
}
}
protected void ddl_Location_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
DataTable dt = GetLocation(ddl_Location.SelectedValue);
if (dt.Rows.Count > 0)
{
DataRow dr = dt.Rows[0];
this.MainBody.Attributes.Add("onload", "load(" + dr["Latitude"].ToString() + "," + dr["Longitude"].ToString() + ",'" + dr["updtime"].ToString() + "')");
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
private DataTable GetLocation(string UID)
{
try
{
string strconn = "Data Source=localhost;Initial Catalog=GPSDB;User Id=GPSUser;Password=gpsuser;";
SqlConnection conn = new SqlConnection(strconn);
string strcmd = "select Latitude,Longitude,UpdTime from GPSDB..gpstrace where UID=@UID";
SqlCommand cmd = new SqlCommand(strcmd, conn);
cmd.Parameters.AddWithValue("@UID", UID);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt=new DataTable();
da.Fill(dt);
return dt;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
如此一來,就大功告成了,但或許有些人會有些遺問,那麼MAP上,可以自訂一些東西,例如不給搜尋列,這都是可以做到的,可以參考Google Map API Examples,這裡就有很多詳細的說明.
感覺起來,GPS定位的想法部份,好像到此就沒了,但在這過程中也發現到,其實Google Map有出Mobile版的,而它的定位可不只是局限在GPS衛星訊號,而是可以用手機的訊號去定位,也就是說,他是透過手機與基地台之間的傳輸來計算出所在位置,這樣就可以不受到手機沒有GPS功能模組或收不到衛星訊號所限制,這個概念其實也不算新,記得幾年前的Run!PC雜誌上就有篇文章是在介紹這個的,採用的技術是Java.
不過不管如何,可以預見的是,這個的應用會愈來愈多元,誰說未來還要自己去用電腦下載圖資再更新到自己的GPS裝置上,裝置上的地圖永遠會是最新的,加上Street View,也不用去看那電腦畫出來的3D的道路圖了,或許3G或無線上網的普及,這些運用將會更廣泛.
http://maps.google.com/maps?q=台北縣中和市莒光路
當我們知道經緯度後,只要將數據套到以下網址即可.
http://maps.google.com/maps?q=25.048346%2c121.516396
在參數q=後面,就可以加上經緯度了.
25.048346是Latitude緯度
%2c是空格
121.516396就是Longitude經度了.

而另一種做法就比這個複雜一點,要使用Google API來做,首先,要使用google API就必需要有google的帳號,沒帳號是無法申請的,當有google的帳號後,就可以到http://code.google.com/apis/maps/signup.html開始申請了.

最下方My web site URL就輸入各位的URL囉,如果輸入的與執行google map api的URL不同,那就無法執行了.所以這個URL務必輸入正確, 輸入正確的URL並將上方的CheckBox打勾後,就可以按Generate API Key了,如果已經登入GOOGLE的,就不會再跳登入畫面,之後就會跳到另一個畫面,上面就有Key及Example Code了,當有了這些,就可以開始自己寫Code了.
基本上,因為主要是Demo用的,所以設計介面很簡單.
上面就一個DropDownList,因為先前的範例資料的關係,先手動在ITEM上加上1跟2.
而下方的地圖,就跟申請API時的Example Code一樣. 原始碼如下 :
< %@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
< !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>GPS 位置地圖< /title>
< script src="http://maps.google.com/maps?file=api&v=2&key=輸入你的Key"
type="text/javascript">< /script>
< script src="http://www.google.com/uds/api?file=uds.js&v=1.0&key=輸入你的Key"
type="text/javascript">< /script>
< script src="http://www.google.com/uds/solutions/localsearch/gmlocalsearch.js" type="text/javascript">< /script>
< style type="text/css"> @import url("http://www.google.com/uds/css/gsearch.css");
@import url("http://www.google.com/uds/solutions/localsearch/gmlocalsearch.css");
< /style>
< script type="text/javascript">
//< ![CDATA[
function load(x,y,LocationName) {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
var point = new GLatLng(x,y);
map.setCenter(point, 16);
map.addOverlay(new GMarker(point));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GScaleControl());
var lsc = new google.maps.LocalSearch();
map.addControl(new google.maps.LocalSearch() , new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,20)));
map.openInfoWindowHtml (map.getCenter(), LocationName);
}
}
//]]>
< /script>
< /head>
< body id="MainBody" runat="server">
< form id="form1" runat="server">
< div>
< asp:DropDownList ID="ddl_Location" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddl_Location_SelectedIndexChanged"
Width="500px">
< asp:ListItem>1< /asp:ListItem>
< asp:ListItem Value="2">2< /asp:ListItem>
< /asp:DropDownList>< br />
< br />
< div id="map" style="width: 500px; height: 400px">
< /div>
< /div>
< /form>
< /body>
< /html>
只要將"輸入你的Key"的地方置換為你在Google MAP API申請到的Key即可.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.QueryString.HasKeys())
{
string longitude = Request.QueryString.Get("lon");
string latitude = Request.QueryString.Get("lat");
string LN = Request.QueryString.Get(Server.UrlDecode("LN"));
this.MainBody.Attributes.Add("onload", "load(" + longitude + "," + latitude + ",'" + LN + "')");
}
else
{
DataTable dt = GetLocation(ddl_Location.SelectedValue);
if (dt.Rows.Count > 0)
{
DataRow dr = dt.Rows[0];
this.MainBody.Attributes.Add("onload", "load(" + dr["Latitude"].ToString() + "," + dr["Longitude"].ToString() + ",'" + dr["updtime"].ToString() + "')");
}
}
}
}
protected void ddl_Location_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
DataTable dt = GetLocation(ddl_Location.SelectedValue);
if (dt.Rows.Count > 0)
{
DataRow dr = dt.Rows[0];
this.MainBody.Attributes.Add("onload", "load(" + dr["Latitude"].ToString() + "," + dr["Longitude"].ToString() + ",'" + dr["updtime"].ToString() + "')");
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
private DataTable GetLocation(string UID)
{
try
{
string strconn = "Data Source=localhost;Initial Catalog=GPSDB;User Id=GPSUser;Password=gpsuser;";
SqlConnection conn = new SqlConnection(strconn);
string strcmd = "select Latitude,Longitude,UpdTime from GPSDB..gpstrace where UID=@UID";
SqlCommand cmd = new SqlCommand(strcmd, conn);
cmd.Parameters.AddWithValue("@UID", UID);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt=new DataTable();
da.Fill(dt);
return dt;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
如此一來,就大功告成了,但或許有些人會有些遺問,那麼MAP上,可以自訂一些東西,例如不給搜尋列,這都是可以做到的,可以參考Google Map API Examples,這裡就有很多詳細的說明.
感覺起來,GPS定位的想法部份,好像到此就沒了,但在這過程中也發現到,其實Google Map有出Mobile版的,而它的定位可不只是局限在GPS衛星訊號,而是可以用手機的訊號去定位,也就是說,他是透過手機與基地台之間的傳輸來計算出所在位置,這樣就可以不受到手機沒有GPS功能模組或收不到衛星訊號所限制,這個概念其實也不算新,記得幾年前的Run!PC雜誌上就有篇文章是在介紹這個的,採用的技術是Java.
不過不管如何,可以預見的是,這個的應用會愈來愈多元,誰說未來還要自己去用電腦下載圖資再更新到自己的GPS裝置上,裝置上的地圖永遠會是最新的,加上Street View,也不用去看那電腦畫出來的3D的道路圖了,或許3G或無線上網的普及,這些運用將會更廣泛.
Google Maps 常用參數說明及相關製作文件介紹
在地圖上您可套用以下任何內置控制件:
map.addControl(new GSmallMapControl()); //加入地圖縮放工具,無拉桿(擇一使用)
map.addControl(new GLargeMapControl()); //加入地圖縮放工具,有拉桿(擇一使用)
map.addControl(new GScaleControl()); //加上比例尺
map.addControl(new GMapTypeControl()); //加入地圖切換類型
map.addControl(new GOverviewMapControl()); //位於又下角可折疊縮略圖
map.setCenter(new GLatLng(25.001689, 121.460809), 8); //設定台灣經度,緯度
map.addControl(new google.maps.LocalSearch()); //加入搜尋功能
map.addMapType(G_NORMAL_MAP); //加入一般道路圖(預設)
map.addMapType(G_SATELLITE_MAP); //加入衛星空照圖
map.addMapType(G_PHYSICAL_MAP); //加入地形圖
map.addMapType(G_HYBRID_MAP); //混合地形圖
Google Maps API 內建四種控制項:
1. GLargeMapControl : 適合給大型地圖的控制項。
2. GSmallMapControl : 適合給小型地圖的控制項。
3. GSmallZoomControl : 只有 Zoom Level 的調整,沒有地圖移動控制。
4. GMapTypeControl : 顯示地圖型態切換的控制項。
設置按鈕 CSS 元素。
TextualZoomControl.prototype.setButtonStyle_ = function(button) {
button.style.textDecoration = "underline";
button.style.color = "#0000cc";
button.style.backgroundColor = "white";
button.style.font = "small Arial";
button.style.border = "1px solid black";
button.style.padding = "2px";
button.style.marginBottom = "3px";
button.style.textAlign = "center";
button.style.width = "6em";
button.style.cursor = "pointer";
}
http://www.webpage.idv.tw/maillist/maillist3/skill/09/09.htm
map.addControl(new GSmallMapControl()); //加入地圖縮放工具,無拉桿(擇一使用)
map.addControl(new GLargeMapControl()); //加入地圖縮放工具,有拉桿(擇一使用)
map.addControl(new GScaleControl()); //加上比例尺
map.addControl(new GMapTypeControl()); //加入地圖切換類型
map.addControl(new GOverviewMapControl()); //位於又下角可折疊縮略圖
map.setCenter(new GLatLng(25.001689, 121.460809), 8); //設定台灣經度,緯度
map.addControl(new google.maps.LocalSearch()); //加入搜尋功能
map.addMapType(G_NORMAL_MAP); //加入一般道路圖(預設)
map.addMapType(G_SATELLITE_MAP); //加入衛星空照圖
map.addMapType(G_PHYSICAL_MAP); //加入地形圖
map.addMapType(G_HYBRID_MAP); //混合地形圖
Google Maps API 內建四種控制項:
1. GLargeMapControl : 適合給大型地圖的控制項。
2. GSmallMapControl : 適合給小型地圖的控制項。
3. GSmallZoomControl : 只有 Zoom Level 的調整,沒有地圖移動控制。
4. GMapTypeControl : 顯示地圖型態切換的控制項。
設置按鈕 CSS 元素。
TextualZoomControl.prototype.setButtonStyle_ = function(button) {
button.style.textDecoration = "underline";
button.style.color = "#0000cc";
button.style.backgroundColor = "white";
button.style.font = "small Arial";
button.style.border = "1px solid black";
button.style.padding = "2px";
button.style.marginBottom = "3px";
button.style.textAlign = "center";
button.style.width = "6em";
button.style.cursor = "pointer";
}
http://www.webpage.idv.tw/maillist/maillist3/skill/09/09.htm
2009年5月14日 星期四
Google Maps API 輸入地址轉經緯度,並產生地圖程式分享
Google Maps API 輸入地址轉經緯度,並產生地圖程式分享!!
這幾天小小研究了Google Maps API的程式...
因為我們要把My-Life旅遊登錄的商家,都自動產生個地圖頁並附上經緯度,
這樣就能夠讓遊客很容易的就知道商家的位置,
有GPS的遊客也很容易的就找到商家的經緯度,可以做定位!
因為在找相關資料時,文章非常少,也沒什麼地方討論!!
特別發這帖,希望需要的朋友能參考及交流!!
首先要寫Google Maps API必須要先擁有API KEY
你能夠到以下網址申請
http://code.google.com/apis/maps/signup.html
(一個網址需要申請一個API KEY)
申請完後你能在這個頁面找到些範例程式
http://code.google.com/apis/maps/documentation/examples/index.html
像最簡易的頁面
http://code.google.com/apis/maps/documentation/examples/event-simple.html
多了控制項的頁面
http://code.google.com/apis/maps/documentation/examples/control-simple.html
輸入地址轉座標的頁面
http://code.google.com/apis/maps/documentation/examples/geocoding-simple.html
http://www.my-life.tw/hosting-talk/thread-418-1-1.html
這幾天小小研究了Google Maps API的程式...
因為我們要把My-Life旅遊登錄的商家,都自動產生個地圖頁並附上經緯度,
這樣就能夠讓遊客很容易的就知道商家的位置,
有GPS的遊客也很容易的就找到商家的經緯度,可以做定位!
因為在找相關資料時,文章非常少,也沒什麼地方討論!!
特別發這帖,希望需要的朋友能參考及交流!!
首先要寫Google Maps API必須要先擁有API KEY
你能夠到以下網址申請
http://code.google.com/apis/maps/signup.html
(一個網址需要申請一個API KEY)
申請完後你能在這個頁面找到些範例程式
http://code.google.com/apis/maps/documentation/examples/index.html
像最簡易的頁面
http://code.google.com/apis/maps/documentation/examples/event-simple.html
多了控制項的頁面
http://code.google.com/apis/maps/documentation/examples/control-simple.html
輸入地址轉座標的頁面
http://code.google.com/apis/maps/documentation/examples/geocoding-simple.html
http://www.my-life.tw/hosting-talk/thread-418-1-1.html
利用 Google Maps 查詢地址經緯度 - Geocoding via HTTP 簡易範例
使用 WebClient 類別:
1: // Taipei 101
2: string address = "台北市信義路五段七號101樓";
3:
4: // 查詢經緯度
5: string output = "csv";
6: string key = "ABQIAAAAXDq__hWKi9eMCwnn7LrMCxT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSnSVp_Xlsd4Ph5iyMua7PE5E0x_A";
7: string url = string.Format("http://maps.google.com/maps/geo?q={0}&output={1}&key={2}", address, output, key);
8:
9: WebClient wc = new WebClient();
10:
11: // 讀取結果
12: Stream s = wc.OpenRead(url);
13: StreamReader sr = new StreamReader(s, Encoding.UTF8);
14: string result = sr.ReadToEnd();
15:
16: // 解析 200,8,25.033408,121.564099 (HTTP status code, accuracy, latitude, longitude)
17: string[] tmpArray = result.Split(',');
18: string latitude = tmpArray[2];
19: string longitude = tmpArray[3];
20:
21: MessageBox.Show(string.Format("緯度: {0}, 經度: {1}", latitude, longitude), address,
22: MessageBoxButtons.OK, MessageBoxIcon.Information);使用 HttpWebRequest、
HttpWebResponse 類別:
1: // Taipei 101
2: string address = "台北市信義路五段七號101樓";
3:
4: // 查詢經緯度
5: string output = "csv";
6: string key = "ABQIAAAAXDq__hWKi9eMCwnn7LrMCxT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSnSVp_Xlsd4Ph5iyMua7PE5E0x_A";
7: string url = string.Format("http://maps.google.com/maps/geo?q={0}&output={1}&key={2}", address, output, key);
8:
9: // 送出要求
10: HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
11:
12: // 取得回應
13: HttpWebResponse response = (HttpWebResponse) request.GetResponse();
14:
15: // 讀取結果
16: StreamReader sr = new StreamReader(response.GetResponseStream());
17:
18: // 解析 200,8,25.033408,121.564099 (HTTP status code, accuracy, latitude, longitude)
19: string[] tmpArray = sr.ReadToEnd().Split(',');
20: string latitude = tmpArray[2];
21: string longitude = tmpArray[3];
22:
23: MessageBox.Show(string.Format("緯度: {0}, 經度: {1}", latitude, longitude), address,
24: MessageBoxButtons.OK, MessageBoxIcon.Information);
http://www.dotblogs.com.tw/chhuang/archive/2008/04/03/2593.aspx
Google Map 的中文製作簡介
http://dev.leck.com/gsupport/
1: // Taipei 101
2: string address = "台北市信義路五段七號101樓";
3:
4: // 查詢經緯度
5: string output = "csv";
6: string key = "ABQIAAAAXDq__hWKi9eMCwnn7LrMCxT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSnSVp_Xlsd4Ph5iyMua7PE5E0x_A";
7: string url = string.Format("http://maps.google.com/maps/geo?q={0}&output={1}&key={2}", address, output, key);
8:
9: WebClient wc = new WebClient();
10:
11: // 讀取結果
12: Stream s = wc.OpenRead(url);
13: StreamReader sr = new StreamReader(s, Encoding.UTF8);
14: string result = sr.ReadToEnd();
15:
16: // 解析 200,8,25.033408,121.564099 (HTTP status code, accuracy, latitude, longitude)
17: string[] tmpArray = result.Split(',');
18: string latitude = tmpArray[2];
19: string longitude = tmpArray[3];
20:
21: MessageBox.Show(string.Format("緯度: {0}, 經度: {1}", latitude, longitude), address,
22: MessageBoxButtons.OK, MessageBoxIcon.Information);使用 HttpWebRequest、
HttpWebResponse 類別:
1: // Taipei 101
2: string address = "台北市信義路五段七號101樓";
3:
4: // 查詢經緯度
5: string output = "csv";
6: string key = "ABQIAAAAXDq__hWKi9eMCwnn7LrMCxT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSnSVp_Xlsd4Ph5iyMua7PE5E0x_A";
7: string url = string.Format("http://maps.google.com/maps/geo?q={0}&output={1}&key={2}", address, output, key);
8:
9: // 送出要求
10: HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
11:
12: // 取得回應
13: HttpWebResponse response = (HttpWebResponse) request.GetResponse();
14:
15: // 讀取結果
16: StreamReader sr = new StreamReader(response.GetResponseStream());
17:
18: // 解析 200,8,25.033408,121.564099 (HTTP status code, accuracy, latitude, longitude)
19: string[] tmpArray = sr.ReadToEnd().Split(',');
20: string latitude = tmpArray[2];
21: string longitude = tmpArray[3];
22:
23: MessageBox.Show(string.Format("緯度: {0}, 經度: {1}", latitude, longitude), address,
24: MessageBoxButtons.OK, MessageBoxIcon.Information);
http://www.dotblogs.com.tw/chhuang/archive/2008/04/03/2593.aspx
Google Map 的中文製作簡介
http://dev.leck.com/gsupport/
訂閱:
文章 (Atom)