- CodepublicstaticCoordinate GetCoordinates(string region)
- {
- using (varclient = newWebClient())
- {
- string uri = "http://maps.google.com/maps/geo?q=''" + region +
- "''&output=csv&key=ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1" +
- "-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA";
- string[] geocodeInfo = client.DownloadString(uri).Split('','');
- returnnewpublicstruct Coordinate
- {
- privatedoublelat;
- private
Reverse Geocoding
顾名思义,这个是Geocoding的反操作,我们可以根据经度和纬度来找出该位置的名称。代码如下:
- Codevarmap;
- vargeocoder;
- functionInitializeMap() {
- varlatlng = newgoogle.maps.LatLng(-34.397, 150.644);
- myOptions =
- {
- zoom: 8,
- center: latlng,
- mapTypeId: google.maps.MapTypeId.ROADMAP,
- disableDefaultUI: true
- };
- map = newgoogle.maps.Map(document"), myOptions);
- }
- functionFindLocaiton() {
- geocoder = newgoogle.maps.Geocoder();
- InitializeMap();
- varaddress = document.getElementById("addressinput").value;
- geocoder.geocode({ ''address'': address }, function(results,
Reverse Geocoding in C#
同样用C#也可以实现Reverse Geocoding操作:
- CodestaticstringbaseUri =
- "http://maps.googleapis.com/maps/api/geocode/xml?latlng={0},{1}&sensor=falsestringlocation = string.Empty;
- publicstaticvoidRetrieveFormatedAddress(stringlat, stringlng)
- {
- requestUri = string.Format(baseUri, lat, lng);
- using(WebClient wc = newWebClient())
- {
- stringinxmlElm.Descendants() where
- elm.Name == "status
总结
在这篇文章,我尝试将V3版本的Google Maps API中的最基本和最常用的功能解说清楚。希望这篇文章能帮你顺利完成任务。然后,API中还有很多我没有讨论到的,我将尝试在今后的文章中来讨论。当然希望能得到大家的点评和反馈。
源码下载:http://files.cnblogs.com/sxwgf/GMAP.zip
原文:http://www.cnblogs.com/jz1108/archive/2011/10/21/2220574.html