方法一:JS方法
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript"src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var geocoder;
var map;
function initialize() {
geocoder =new google.maps.Geocoder();
var latlng =new google.maps.LatLng(34.264987, 108.94426900000007);
var myOptions = {
zoom: 12,
center: latlng,
mapTypeId:google.maps.MapTypeId.ROADMAP
}
map =new google.maps.Map(document.getElementById("map_canvas"), myOptions);
//初始化标注添加以下代码
marker =new google.maps.Marker({
title: '',
map: map,
position:latlng
});
var infowindow =new google.maps.InfoWindow({
content: '<strong>love</strong>'
});
infowindow.open(map, marker);
}
functioncodeAddress() {
varaddress = document.getElementById("address").value;
geocoder.geocode({ 'address': address }, function(results, status) {
if(status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
this.marker =newgoogle.maps.Marker({
title: address,
map: map,
position:results[0].geometry.location
});
var infowindow =newgoogle.maps.InfoWindow({
content: '<strong>'+ address +'</strong><br/>'+'纬度: '+ results[0].geometry.location.lat() +'<br/>经度: '+ results[0].geometry.location.lng()
});
infowindow.open(map, marker);
} else {
alert("Geocode was not successful for the following reason:"+ status);
}
alert('纬度: '+ results[0].geometry.location.lat() +'<br/>经度: '+ results[0].geometry.location.lng())
});
}
</script>
</head>
<body onload="initialize()">
<div>
<input id="address" type="text" value="西安市">
<input type="button" value="地址解析" onclick="codeAddress()">
</div>
<div id="map_canvas" style="height:90%;top:30px"></div>
</body>
</html>
方法二:ASP.NET方法
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
//使用方法,g.Latitude=经度,g.Longtitude=纬度
//mapClass.Geo g = new mapClass.Geo("西安");
//Response.Write(g.Latitude + "<br>" +g.Longtitude);
namespace mapClass
{
publicclassGeo
{
///
/// latitude
///
privatestring _latitude = "";
///
/// longtitude
///
privatestring _longtitude = "";
///
/// default constructor
///
publicGeo()
{
}
///
/// construct geo given latitude and longtitude
///
publicGeo(string latitude, stringlongtitude)
{
_latitude = latitude;
_longtitude =longtitude;
}
///
/// construct geo given name of a place
///
publicGeo(string location)
{
stringoutput = "csv";
stringurl = string.Format("http://maps.google.com/maps/geo?q={0}&output={1}",location, output);
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
using (HttpWebResponseresponse = (HttpWebResponse)request.GetResponse())
{
using (StreamReadersr = newStreamReader(response.GetResponseStream()))
{
string[] tmpArray = sr.ReadToEnd().Split(',');
_latitude =tmpArray[2];
_longtitude= tmpArray[3];
}
}
}
catch(System.Net.Sockets.SocketException ex)
{
Console.WriteLine("网络中断");
}
catch(Exception ex)
{
//throw ex;
Console.WriteLine("异常类型:{0}", ex.GetType());
Console.WriteLine("异常信息:{0}", ex.Message);
Console.WriteLine("异常来源:{0}", ex.Source);
Console.WriteLine("异常堆栈:{0}", ex.StackTrace);
Console.WriteLine("内部异常:{0}", ex.InnerException);
}
}
///
/// get latitude
///
publicstring Latitude
{
get{ return _latitude; }
set{ _latitude = value; }
}
///
/// get longtitude
///
publicstring Longtitude
{
get{ return _longtitude; }
set{ _longtitude = value; }
}
}
}
引自:http://www.2cto.com/kf/201203/124622.html
分享到:
相关推荐
这是一个简单的java工程,作用是从一个文件中读取数个地址,通过谷歌地图提供的http网址,获取每个地址的经纬度,并保存到另一个文件中。
根据经纬度获取google地图海拔
一个google map小应用 应用google map api可以获得点的经纬度并且可以根据地理位置名称定位。
(地区经纬度信息获取(利用Google地图API获取).
批量经纬度获取地址软件(需联网使用,含批量 谷歌 经纬度 转 高德 经纬度 功能) 使用方法:双击exe打开软件,提示是否需要生成模板表格,输入是回车则生成表格模板,填写好谷歌数据后保存关闭表格,再双击软件重新...
自己写的一个获取google地点经纬度的小工具,可以自定义保存到指定文件夹下。
GOOGLE地图经纬度批量查询V1.0 输入查询地址,可获取经纬度信息,也可批量操作,具体见软件中说明
地图经纬度互换(百度,高德,谷歌,腾讯,搜狗) 具有以下功能 1、通过经纬度获取地址信息。 2、通过地址信息获取经纬度。 3、高德谷歌经纬度转百度地图经纬度。 4、百度经纬度转高德谷歌经纬度。 注,本程序来自于...
vba《调用Google地图获取地址经纬度填入Excel并存储到数据库》
利用谷歌地图获取对应地名的经纬度源码(C#) 谷歌地图获取经纬度源码
这是我的文章【Google地图经纬度与平面坐标的相互转换、简单地图Demo】的附件,内含无水印世界地图、简单地图demo源码 接到公司派下来的一个任务,让我做一个简单的地图Demo,要求是输入城市名,然后在地图上标记出...
根据GoogleMapApi给出地名获取经纬度,给出经纬度获取地名(Java版本) RT
利用google地图根据地址批量获取经纬度
使用方法:双击软件弹出窗口提示是否需要新建模板,如果有模板的情况下直接点击回车,弹出文件拾取框选择模板表格文件确定执行程序
通过google api获取经纬度,用于网站跟位置相关的信息化
在百度、谷歌、soso、等地图上,对经纬度偏移进行正确的纠偏的最佳技术解决方案,内容包含技术解决与相关获取资料方式!
android安卓绝对可以获取GPS经纬度的google map demo。使用谷歌api,不需要网络,可以直接获取经纬度,获取经纬度写到一个类中,直接调用start,关闭使用stop。 注意要在室外使用! 打开应用,马上开始获取地址,多次...
googleMap根据经纬度获取地理位置,里面有使用代码,只需填入经纬度即可获取地理位置信息
根据输入的地址获取经纬度的信息,百度地图,谷歌地图没有上传
获取经纬度类 利用google地图 源代码