public JsonResult AutoSuggest(string accessToken, string query, string lat, string lng, string types, int radius = 15000) { if (HttpContext.Request.RequestType == "POST") { var newAccessToken = _accessTokenService.GenerateAccessToken(accessToken); if (newAccessToken == null) { return(Json(new { status = "INVALID ACCESSTOKEN" })); } var userId = _accessTokenService.GetUserId(newAccessToken); if (userId == null) { return(Json(new { status = "ERR", accessToken = newAccessToken })); } double latDouble = 0; double lonDouble = 0; lat.Replace('.', ','); lng.Replace('.', ','); if (double.TryParse(lat, out latDouble) && double.TryParse(lng, out lonDouble)) { var places = GoogleAPIRequest.AutoCompleteList(query, new Models.Models.Location() { Latitude = latDouble, Longitude = lonDouble }, radius, types); return(Json(new { status = "OK", places = places, accessToken = newAccessToken })); } else { return(Json(new { status = "LatLon Parse Error", accessToken = newAccessToken })); } } return(Json(new { })); }
/// <summary> /// Returns suggested places or addresses /// </summary> /// <param name="text"></param> /// <returns></returns> public JsonResult AutoComplete(string text) { var userId = User.Identity.GetUserId(); var dispatcher = _dispatcherService.GetAll().First(x => x.UserId == userId); var company = _companyService.GetAll().First(x => x.Id == dispatcher.Company.Id); var cityLocation = company.CityLocation; var suggestions = GoogleAPIRequest.AutoCompleteList(text, cityLocation, 10000, ""); object[] result = new object[suggestions.Count]; for (int i = 0; i < result.Length; i++) { result[i] = new { main_text = suggestions[i].MainText, secondary_text = suggestions[i].Address, placeId = suggestions[i].PlaceId }; } return(Json(new { status = "OK", suggestions = result })); }