/// <summary> /// Retrieves the map with the given request and writes the image bytes to the given target stream. /// </summary> /// <param name="request"></param> /// <param name="targetStream"></param> /// <returns>number of bytes written to the target stream</returns> public int GetMapToStream(StaticMapRequest mapOptions, System.IO.Stream outputStream) { Uri requestUri = new Uri(BaseUri, mapOptions.ToUri()); GoogleSigned signingInstance = GoogleSigned.SigningInstance; if (signingInstance != null) { requestUri = new Uri(signingInstance.GetSignedUri(requestUri)); } int totalBytes = 0; WebRequest request = WebRequest.Create(requestUri); using (WebResponse response = request.GetResponse()) { Stream inputStream = response.GetResponseStream(); int bytesRead = 0; const int BYTE_BUFFER_LENGTH = 4096; byte[] buffer = new byte[BYTE_BUFFER_LENGTH]; do { bytesRead = inputStream.Read(buffer, 0, BYTE_BUFFER_LENGTH); outputStream.Write(buffer, 0, bytesRead); totalBytes += bytesRead; }while(bytesRead > 0); } return(totalBytes); }
Uri SignUri(Uri uri) { if (signingSvc == null) { return(uri); } return(new Uri(signingSvc.GetSignedUri(uri))); }
/// <summary> /// Gets a Uri with a signature calculated. /// See https://developers.google.com/maps/documentation/maps-static/get-api-key /// for more info. /// </summary> /// <param name="signingInfo"></param> /// <returns></returns> public string ToUriSigned(GoogleSigned signingInfo = null) { if (signingInfo == null) { signingInfo = GoogleSigned.SigningInstance; } Uri reqUri = this.ToUri(); return(signingInfo.GetSignedUri(reqUri)); }
protected virtual StreamReader GetStreamReader(Uri uri, GoogleSigned signingInstance) { if (signingInstance != null) { uri = new Uri(signingInstance.GetSignedUri(uri)); } WebResponse response = WebRequest.Create(uri).GetResponse(); StreamReader sr = new StreamReader(response.GetResponseStream()); return(sr); }