Exemple #1
0
        private void Adapter_ItemClick(object sender, int e)
        {
            GooglePlaceResult res  = adapter.Data[e];
            string            json = JsonConvert.SerializeObject(
                new Place
            {
                GooglePlaceId = res.place_id,
                Latitude      = new decimal(res.geometry.location.lat),
                Longitude     = new decimal(res.geometry.location.lng),
                Name          = res.name
            }
                );

            Intent myIntent = new Intent(this, typeof(CreateFinishActivity));

            myIntent.PutExtra("JSON", json);
            SetResult(Result.Ok, myIntent);
            Finish();
        }
        /// <summary>
        /// Calls Google places API
        /// </summary>
        /// <param name="query">Search term to query</param>
        /// <param name="coordinate">Coordinate to bias the result</param>
        /// <param name="radius">Radius to bias the result</param>
        /// <param name="status">Response status</param>
        /// <returns>List of Google Places</returns>
        ///
        public List <GooglePlace> Search(string query, GeoCoordinate coordinate, long?radius, out GoogleResponseStatus status)
        {
            string location = (coordinate != null) ? String.Format("{0},{1}", coordinate.Latitude, coordinate.Longitude) : null;
            var    uri      = String.Format(MapUri, query, ApiKey, Convert.ToString(radius), location);

            uri = GoogleRequestHelper.SetQuotaUser(uri, this.QuotaUser);
            var httpRequest = (HttpWebRequest)HttpWebRequest.Create(uri);

            httpRequest.ContentType = "application/json; charset=utf-8";
            httpRequest.Method      = WebRequestMethods.Http.Get;
            httpRequest.Accept      = "application/json";

            using (HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse())
            {
                using (var sr = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var json = sr.ReadToEnd();
                    return(GooglePlaceResult.ProcessResult(json, out status));
                }
            }
        }