0
晚上好, j試圖從用戶檢索數據,但問題iç,我無法處理因爲「,」經度和緯度的座標,我不知道如何處理這些給,我試圖與parsefloat但是沒有結果,謝謝 代碼控制器動作:保持來自ajax的地理座標
public ActionResult GetNeaarByLocations(string CurrentLat, string CurrentLng)
{
using (GeolocationTestEntities context = new GeolocationTestEntities())
{
var CurrentLocation = DbGeography.FromText("POINT(" + CurrentLat + " " + CurrentLng + ")");
//var CurrentLocation = DbGeography.FromText("POINT(36,806494799999996 10,181531600000001)");
var places = (from u in context.schoolinfo orderby u.Location.Distance(CurrentLocation)
select u).Take(4).Select(x=>new schoollinfo(){ Name = x.name ,Lat = x.Location.Latitude, Lng = x.Location.Longitude,Distance = x.Location.Distance(CurrentLocation)});
var nearschools = places.ToList();
return Json(nearschools , JsonRequestBehavior.AllowGet);
}
}
,這是代碼的Ajax:
jQuery.ajax({
cache: false,
type: "POST",
url: "@Url.Action("GetNeaarByLocations")",
dataType: "json",
contentType: "application/json;charset=utf-8",
data: JSON.stringify({ CurrentLng:currentLatLng.longitude, CurrentLat: currentLatLng.latitude }),
success: function (data) {
if (data != undefined) {
$.each(data, function (i, item) {
addMarker(item["lat"], item["lng"], "Click to get directions");
})
}
},
failure: function (errMsg) {
alert(errMsg);
}
});
感謝所有。