Ejemplo n.º 1
0
        /// <summary>
        /// Resolve a Geocode (synchronously)
        /// </summary>
        /// <param name="googleRequest"></param>
        /// <param name="timeout"></param>
        /// <returns></returns>
        /// <remarks>Does not work as of the moment</remarks>
        public GoogleGeocodeResponse ResolveGeoCode(GoogleGeocodeRequest googleRequest, int timeout)
        {
            var requestUrl = GenerateRequestUrl(googleRequest);
            var request = (HttpWebRequest)HttpWebRequest.Create(requestUrl);
            request.Method = "GET";

            request.BeginGetResponse(ResponseCallbackSync, new List<object> { request, googleRequest });
            _autoResetEvent.WaitOne(timeout);
            return _syncGoogleResponse;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Resolve a Geocode (asynchronously)
        /// </summary>
        /// <param name="googleRequest"></param>
        public void ResolveGeoCodeAsync(GoogleGeocodeRequest googleRequest)
        {
            var requestUrl = GenerateRequestUrl(googleRequest);
            var request = (HttpWebRequest)HttpWebRequest.Create(requestUrl);
            request.Method = "Post";

            try
            {
                request.BeginGetResponse(ResponseCallback, new List<object> { request, googleRequest });
            }
            catch (Exception e)
            {
                GeocodeFailed(e.Message, e);
            }
        }
Ejemplo n.º 3
0
 private void SyncronizedGeocodeNotFoundHandler(GoogleGeocodeResponse response, GoogleGeocodeRequest request)
 {
     _syncGoogleResponse = response;
     _autoResetEvent.Set();
 }
Ejemplo n.º 4
0
 private string GenerateRequestUrl(GoogleGeocodeRequest googleRequest)
 {
     var language = googleRequest.Language.HasValue
                        ? Enum.GetName(typeof (GoogleMapsLanguage), googleRequest.Language.Value).Replace("_", "-")
                        : string.Empty;
     var bounds = googleRequest.BoundSouthWestLat != null && googleRequest.BoundNorthEastLat != null
                      ? googleRequest.BoundSouthWestLat+ "," + googleRequest.BoundSouthWestLong+ "|" +
                        googleRequest.BoundNorthEastLat + "," + googleRequest.BoundNorthEastLong
                      : string.Empty;
     var latlong = googleRequest.Latitude == null
                       ? string.Empty
                       : googleRequest.Latitude + "," + googleRequest.Longitude;
     var address = string.IsNullOrEmpty(googleRequest.Address)
                       ? string.Empty
                       : Uri.EscapeDataString(googleRequest.Address);
     var requestUrl =
         !string.IsNullOrEmpty(latlong)
             ? string.Format(Reverse_Geocode_Request_Url, _appId, latlong, googleRequest.Sensor.ToString().ToLower())
             : string.Format(Request_Url, _appId, address, bounds, language, googleRequest.Sensor.ToString().ToLower())
         ;
     return requestUrl;
 }