0
좋은 저녁, j는 ","경도와 위도로 인해 좌표를 처리 할 수 없다는 문제가 있지만 사용자에게 데이터를 가져 오려고합니다. 이러한 처리 방법을 모르겠습니다. , 나는에서는 parseFloat로하지만 결과없이 시도하면 코드 컨트롤러 액션 감사합니다 :아약스에서 지리 좌표를 유지하십시오
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);
}
}
를이 코드 아약스입니다 :
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);
}
});
덕분에 모든. Ajax를 삭제하는 것입니다 위해