62,271
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
namespace YourNameSpace
{
/// <summary>
/// a class for latitude and longtitude
/// </summary>
[Serializable]
public class Geo
{
/// <summary>
/// latitude
/// </summary>
private string _latitude = "";
/// <summary>
/// longtitude
/// </summary>
private string _longtitude = "";
/// <summary>
/// default constructor
/// </summary>
public Geo()
{
}
/// <summary>
/// construct geo given latitude and longtitude
/// </summary>
/// <param name="latitude"></param>
/// <param name="longtitude"></param>
public Geo(string latitude, string longtitude)
{
_latitude = latitude;
_longtitude = longtitude;
}
/// <summary>
/// construct geo given name of a place
/// </summary>
/// <param name="location"></param>
public Geo(string location)
{
string output = "csv";
string url = string.Format("http://maps.google.com/maps/geo?q={0}&output={1}", location, output);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (StreamReader sr = new StreamReader(response.GetResponseStream()))
{
string[] tmpArray = sr.ReadToEnd().Split(',');
_latitude = tmpArray[2];
_longtitude = tmpArray[3];
}
}
/// <summary>
/// get latitude(纬度)
/// </summary>
public string Latitude
{
get { return _latitude; }
set { _latitude = value; }
}
/// <summary>
/// get longtitude(经度)
/// </summary>
public string Longtitude
{
get { return _longtitude; }
set { _longtitude = value; }
}
}
}
<!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" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gbk"/>
<title>Google 地图 JavaScript API 示例: 定制图标</title>
<script src="http://ditu.google.cn/maps?file=api&v=2&key=ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA&hl=zh-CN"
type="text/javascript"></script>
<style type=text/css>
ul{
float:left;
}
</style>
<script type="text/javascript">
var map = null;
var geocoder = null;
function showAddress(address, html, level) {
if (geocoder) {
geocoder.getLatLng(address,
function (point) {
if (!point) {
alert("不能解析: " + address);
} else {
map.setCenter(point, level);
var marker = new GMarker(point);
map.clearOverlays();
map.addOverlay(marker);
marker.openInfoWindowHtml(html);
GEvent.addListener(marker, "click",
function () {
marker.openInfoWindowHtml(html);
});
}
});
}
}
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(1111111, 2222222), 8);
var mapControl = new GMapTypeControl();
map.addControl(new GLargeMapControl());
geocoder = new GClientGeocoder();
showAddress("北京", '我老家在这里', 8);
}
}
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
经度:<input type=text id="jd"> 纬度:<input type=text id="wd"><input type=button value="设置指定坐标" onclick="map.setCenter(new GLatLng(document.getElementById('jd').value,document.getElementById('wd').value), 8);">
<div id="map_canvas" style="width: 600px; height: 300px"></div>