Discussion:
Nearest Address
(too old to reply)
Fred Block
2008-12-23 15:20:59 UTC
Permalink
Hi All,

I'm working with the MapPoint Web Service and the following call fails when
an address cannot be located (Object reference not set to an instance of an
object.); working in VB 2008:

Address = returnedLocations(0).Address.AddressLine ' Location object.

NOTE: returnedLocations(0) is the first address that would be returned. The
lat/long I'm using that causes the error is: latitude: 41.38232;
longitude: -72.36272.

How can I find the nearest address if one exists? Can someone point me to a
solution and a way to trap this error if an address is not found?

Thanks in advance!

Kind regards - Fred
Derek Chan
2008-12-31 14:58:05 UTC
Permalink
Fred,

A simple null check on the returnedLocations will determine if any address
was returned at all. I'd need to know what MWS call you made to get your
results back to be specific, but in general MWS can never guarantee that the
locations returned will be not be empty (null) so its best to account for it.

Hope that helps,
--
Infusion Development
http://www.infusion.com
Post by Fred Block
Hi All,
I'm working with the MapPoint Web Service and the following call fails when
an address cannot be located (Object reference not set to an instance of an
Address = returnedLocations(0).Address.AddressLine ' Location object.
NOTE: returnedLocations(0) is the first address that would be returned. The
lat/long I'm using that causes the error is: latitude: 41.38232;
longitude: -72.36272.
How can I find the nearest address if one exists? Can someone point me to a
solution and a way to trap this error if an address is not found?
Thanks in advance!
Kind regards - Fred
Fred Block
2008-12-31 16:43:30 UTC
Permalink
Hi Derek,

Thanks for the reply. The call follows this other question. It also appears
that an actual address always "appears" to have an Entity.ID value of "0"
(when tested using: returnedLocations(i).Entity.ID). Is this a known fact
that zero (0) is used for addresses or something I stumbled on and cannot
trust?

Here is the code for the call that occasionally does not get me an address:

findService = New FindServiceSoap
findService.PreAuthenticate = True
findService.Credentials = myCredentials
findService.Url =
"http://findv3.staging.mappoint.net/Find-30/FindService.asmx"

Dim myLatLong As New LatLong() ' Create instance.
myLatLong.Latitude = Latitude
myLatLong.Longitude = Longitude

Dim returnedLocations() As Location
returnedLocations = findService.GetLocationInfo(myLatLong,
My.Settings.MapPointDataSourceName, Nothing)


Thanks again in advance! Happy New Year!

Kind regards - Fred

###
Post by Derek Chan
Fred,
A simple null check on the returnedLocations will determine if any address
was returned at all. I'd need to know what MWS call you made to get your
results back to be specific, but in general MWS can never guarantee that the
locations returned will be not be empty (null) so its best to account for it.
Hope that helps,
--
Infusion Development
http://www.infusion.com
Post by Fred Block
Hi All,
I'm working with the MapPoint Web Service and the following call fails when
an address cannot be located (Object reference not set to an instance of an
Address = returnedLocations(0).Address.AddressLine ' Location object.
NOTE: returnedLocations(0) is the first address that would be returned. The
lat/long I'm using that causes the error is: latitude: 41.38232;
longitude: -72.36272.
How can I find the nearest address if one exists? Can someone point me to a
solution and a way to trap this error if an address is not found?
Thanks in advance!
Kind regards - Fred
Loading...