转:Virtual Earth and AJAX--Part Three

 最后一篇了。发现最近真的懒了,都是转帖了,唉……难道所有的博客都是这样的命运吗?哈哈,一定会努力的

引用地址:http://virtualearth.spaces.live.com/blog/cns!2BBC66E99FDCDB98!536.entry

Tutorial Part 3 - AJAX and Virtual Earth

In part 2 of this tutorial we got the AJAX stuff working, but all the app did was echo back it's input - not terribly exciting. Today we’ll add some simple code to the server component to make a call to the MapPoint Web Service (MWS) to reverse-geocode the coordinate passed in. Reverse geocoding is taking a point on Earth and determining what the corresponding Street Address, City, County, etc… are. Start by trying the application out. When you click the link below the map, notice that you are now presented the approximate address of the center marker on the map.

 

[Note: there will be a part 4 of the tutorial a well - I've had some requests from developers to add other server side functionality and turn on birds eye view. I'll add that in the next day or 2]

 

There aren’t any changes in the client side JavaScript since part 2 – All of the changes are in the Server component. Download the C# source here. You’ll recall from part 2 that the server is responding with javascript telling the browser to present a returned string as the HTML for a DIV tag. We’ve added a function GetLocationInfo() that makes the call to MWS and gets the street address. Lets look at that code.

 

First up, we get a reference to MWS's Find Service. you'll need to fill in your own MWS credentials if building this on your own, which you can do here.

 

FindServiceSoap findService = new FindServiceSoap();

findService.Credentials = new System.Net.NetworkCredential("DEVID","DEVPW");

 

Next up, Create a LatLong object corresponding to the coordinate passed in from the client:

 

LatLong ll = new LatLong();

ll.Latitude = Y;

ll.Longitude = X;

 

We need to tell MWS that we want full street address information returned, not just city state and postcode:

 

GetInfoOptions myOptions = new GetInfoOptions();

myOptions.IncludeAllEntityTypes = true;

myOptions.IncludeAddresses = true;

 

Finrally, we make the call to MWS to do the acual Reverse Geocoding. To keep things simple, we'll return the DIsplay text for the first candidate returned, since they are ordered from best match to least exact match.

 

Location[] locs;

locs = findService.GetLocationInfo(ll, "MapPoint.NA", myOptions);

 

RevGeoResult = locs[0].Entity.DisplayName;

 

That does it for the base of this tutorial. I hope it has been helpful to give you a little peek into the goodness of AJAX and will encourage you to apply it in your own applications. As mentioned above, I'll continue with a part 4 to add some more web service calls and turn on birds eye imagery.

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值