Finding Entities with the MapPoint Web Service Find APIs - Getting Entities from Latitude/Longitude (Page 4 of 4 )
We have looked at find service methods that take place names and addresses and return the corresponding latitude/longitude and other entity information. To find entity (or address) information for any given latitude/longitude, use the FindServiceSoap.GetLocationInfo; it gives you entity information for any given latitude and longitude. The GetLocationInfo method takes theGetInfoOptionsobject as an argument, along with a latitude/longitude and a data source name as a string. TheGetLocationInfoobject gives you control to decide which entity types you want using theGetInfoOptions.EntityTypesToReturnfield; you also have the option to obtain addresses for a given latitude/longitude (if available) using theGetInfoOptions. IncludeAddressesflag. The following code shows how to use theGetLocationInfo method:
//Create a find service soap proxy
FindServiceSoap findService = new FindServiceSoap();
//Take an example lat long information that you want to
//find using GetLocationInfo
LatLong latlong = new LatLong();
latlong.Latitude = 47.682;
latlong.Longitude = -122.132;
//Define get info options object
GetInfoOptions options = new GetInfoOptions();
//I'm looking only for cities
options.IncludeAllEntityTypes = false;
options.EntityTypesToReturn = new string[] {"PopulatedPlace"};
//Define a field to hold returned
locations
Location[] returnedLocations;
//Call GetLocationInfo with "MapPoint.NA" data source
returnedLocations = findService.GetLocationInfo(latlong, "MapPoint.NA", options);
//Get entity information
for(int i = 0; i < returnedLocations.Length; i++)
{
Console.WriteLine(returnedLocations[i].Entity.DisplayName);
}
When I’m querying for corresponding entities for the latitude/longitude, I limit my query to a city (the entity namePopulatedPlace) using theEntityTypesToReturnfield; it is important to remember that you must set theIncludeAllEntityTypesto false when you request specific entities.
This method is not a direct inverse to theFindServiceSoap.FindAddressmethod, so if you call theFindServiceSoap.FindAddressmethod to obtain latitude/longitude for an address and pass that latitude/longitude to theFindServiceSoap.GetLocationInfomethod, the resulting address won’t match your original address because of the internal representation of the address data; in MapPoint data sources, addresses are stored in address range blocks along the streets, and the interpolation algorithms are used to calculate the address for a given latitude/longitude and vice versa. So, the addresses returned by theFindServiceSoap.GetLocationInfoare approximations of the original address; in fact, this method returns an array of four possible addresses for any given latitude/longitude in increasing order of the distance from the given latitude/longitude.
Please check back next week for the conclusion to this article.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
|
This article is excerpted from chapter six of the book Programming MapPoint in .NET, written by Chandu Thota (O'Reilly; ISBN: 0596009062). Check it out today at your favorite bookstore. Buy this book now.
|
|