public void Done(Object context, Response response) { if (context is GReverseClientGeocoder) { GReverseClientGeocoder reverseGeoCoder = (GReverseClientGeocoder)context; SearchResponse(reverseGeoCoder, response); } }
public void ReadProgress(Object context, int bytes, int total) { if (context is GReverseClientGeocoder) { GReverseClientGeocoder reverseGeoCoder = (GReverseClientGeocoder)context; reverseGeoCoder._listener.ReadProgress(bytes, total); } }
private static void SearchResponse(GReverseClientGeocoder reverseGeoCoder, Response response) { MapPoint[] mapPoints = null; Exception ex = response.GetException(); if (ex != null || response.GetCode() != HttpStatusCode.OK) { if (reverseGeoCoder._listener != null) { reverseGeoCoder._listener.Done(reverseGeoCoder._searchAddress, null); } return; } try { Result result = response.GetResult(); result.GetAsString("name"); int resultCount = result.GetSizeOfArray("Placemark"); if (resultCount > 0) { mapPoints = new MapPoint[resultCount]; for (int i = 0; i < resultCount; i++) { mapPoints[i] = new MapPoint(); mapPoints[i].Name = result.GetAsString("Placemark[" + i + "].address"); string location = result.GetAsString("Placemark[" + i + "].Point.coordinates"); GeoLatLng latLng = MapLayer.FromStringToLatLng(location); mapPoints[i].SetPoint(latLng); } if (reverseGeoCoder._addressCache.Count > 24) { for (int j = 0; j < 12; j++) { ICollection keys = reverseGeoCoder._addressCache.Keys; foreach (var o in keys) { reverseGeoCoder._addressCache.Remove(o); break; } } } reverseGeoCoder._addressCache.Add(mapPoints[0].Name, mapPoints[0]); } } catch (Exception) { } if (reverseGeoCoder._listener != null) { reverseGeoCoder._listener.Done(reverseGeoCoder._searchAddress, mapPoints); } }