问题
Can somebody explain me difference between these pieces of code? What is the role of GeoCoordinate property in GeocodeQuery?
#1 - this works only with internet connection
GeocodeQuery geocodeQuery = new GeocodeQuery();
geocodeQuery.GeoCoordinate = new GeoCoordinate();
geocodeQuery.SearchTerm = "London";
IList<MapLocation> locations = await geocodeQuery.GetMapLocationsAsync();
#2 - this works without internet connection
// my location
Geolocator geolocator = new Geolocator();
geolocator.DesiredAccuracy = PositionAccuracy.High;
Geoposition position = await geolocator.GetGeopositionAsync();
// geocode query
GeocodeQuery geocodeQuery = new GeocodeQuery();
geocodeQuery.GeoCoordinate = position.Coordinate.ToGeoCoordinate();
geocodeQuery.SearchTerm = "London";
IList<MapLocation> locations = await geocodeQuery.GetMapLocationsAsync();
回答1:
The GeoCoordinate property is the location upon which to center the query.
The GeocodeQuery will find locations near the specified location.
I would assume that if you don't specify a location it makes a network request to try and identify your location. (Possibly by a reverse IP lookup or to attempt to obtain your current location based on public WiFi hotspot data.)
This is based on the query falling back to use current location if no location is specified.
Also note that if the user has not downloaded local (to the query center / geocoordinate) maps data then I would expect a network request to be necessary in that scenario too.
Note also that some maps data will be cached so that may impact your testing of this also.
来源:https://stackoverflow.com/questions/19139228/geocodequery-geocoordinate-property