I would like to pass the longitude / latitude results from google api places to my MVC application route values. I am not sure how to get it to my route values or how to return javascript to html values. Right now
var result = autocomplete.getPlace();
returns undefined. Thus, it does not even look like work, although autocomplete for places works fine.
var input = document.getElementById('location');
var options = {
types: ['(cities)'],
componentRestrictions: { country: "us" }
};
var autocomplete = new google.maps.places.Autocomplete(input, options);
var t = 2;
var result = autocomplete.getPlace();
var i = 1;
Here is my form that has an input field and a script tag where the location is. I am trying to get lon / lat values for route values of 5.6
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js? v=3.exp&sensor=false&libraries=places"></script>
@{
var routeValues = new RouteValueDictionary();
routeValues.Add("Longitude", "5");
routeValues.Add("Latitude", "6");
}
@using (Html.BeginForm("Results", "Home", routeValues, FormMethod.Post))
{
<p>
<input type="text" name="location" id="location" placeholder="Search For A Studio" />
</p>
<p>
<input class="btn btn-primary btn-lg" value='Submit' type="submit"/>
</p>
}
Here is my action in the controller
public ActionResult Results(string longitude, string latitude)
{
var repo = new YogaSpaceRepository();
DbGeography myLocation = DbGeography.FromText("POINT(-122.453164 37.723057)");
IQueryable<YogaSpace> spaces = repo.AllWithinDistance(myLocation);
return View(spaces);
}
* UPDATE - autocomplete.getPlace() . javascript onclick . , !
(/).
, lat/lon, , , , , , , .
var input = document.getElementById('location');
var options = {
types: ['(cities)'],
componentRestrictions: { country: "us" }
};
var autocomplete = new google.maps.places.Autocomplete(input, options);
function getGeometry() {
var place = autocomplete.getPlace();
var lat = place.geometry.location.lat;
var lon = place.geometry.location.lon;
}