保持来自ajax的地理坐标
问题描述:
晚上好, 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);
}
});
感谢所有。
答
我们需要LNG转换&兰特翻番
var currentLatLng = position.coords;
var Lat = currentLatLng.latitude;
var Lng = currentLatLng.longitude;
var LatDouble = parseFloat(Lat);
var LngDouble = parseFloat(Lng);
对Ajax是删除ATT字符串化
data: JSON({ CurrentLng:LngDouble , CurrentLat: LatDouble }),