开发者

.NET How to find CivicAddress?

开发者 https://www.devze.com 2023-01-18 23:26 出处:网络
this code returns an empty string. What can I do to return something please? CivicAddressResolver civicResolver = new CivicAddressResolver();

this code returns an empty string. What can I do to return something please?

CivicAddressResolver civicResolver = new CivicAddressResolver();
CivicAddress c = civicResolver.Re开发者_Python百科solveAddress(new GeoCoordinate(39,77));
textBlock1.Text = c.City;


The MSDN documentation for CivicAddressResolver.ResolveAddress() suggests that checking c.IsUnknown before trying to access c.City would be a good idea.


From the MSDN docs (phone specific version):

This method is not implemented in the current release.

I would think that this is why you are not getting a result on Windows Phone 7.
Hopefully this functionality will be available soon. (And preferably via an OTA update.)

If you are not doing this on the phone please retag this question appropriately.


This suggests access to Alot of data: street/address numbers for every city/town in whatever subset of the world they choose to support. I have trouble believing that this would ever be included on the phone itself. Maybe eventually made available via web service? In which case, using CivicAddressResolver.ResolveAddressAsync Method would be useful.


Getting the civic address doesn't appear to be supported on any platform. I've been looking at using it on the desktop and found I was getting the same behaviour. So I did some digging with .NET reflector and found that the resolve address call doesn't actually have any implementation that matches the semantics of what the call implies:

public CivicAddress ResolveAddress(GeoCoordinate coordinate)
{
    if (coordinate == null)
    {
        throw new ArgumentNullException("coordinate");
    }
    if (coordinate.IsUnknown)
    {
        throw new ArgumentException("coordinate");
    }
    return coordinate.m_address;
}

I.e. there is no actual resolution of the coordinate to the civic address. It just returns the default initialised address which is never set.

When I dug deeper into the actual GeoCoordinateWatcher implementation I found that it checks to see if it can query lat/long or civic addresses from the underlying location provider. If it can query the lat/long it will always query that only and never get the civic address.

Getting back to the semantics of the .NET API, it implies that you look up a lat/long location and then perform a separate resolution to a civic address. That isn't how the underlying (COM) API actually works. When you query the API for a location you ask for either a lat/long report or a civic address report - you don't get one and then resolve to the other.

So in short I have concluded that the .NET implementation is half baked and was never tested properly. I'm going to write my own .NET wrapper around the underlying COM API, which unfortunately is not something you can do for WinPhone.


There really isn't enough information here to comment anything. We need to know what ResolveAddress does. What do you want it to return? It seems like whatever you are doing can't find the long/lat (I assume) you are sending in.

Depending on what you want to do, you should return a null CivicAddress if it can't find the CivicAddress you are looking for and then do a null check before assigning o the textBlock1 control.

0

精彩评论

暂无评论...
验证码 换一张
取 消