2017-10-11 9 views
0

おはようございます、 jは、ユーザーからデータを取得しようとしていますが、 "経度と緯度"のためにコードを処理できないという問題があります。これらをどのように扱うかわかりません、私は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); 
       } 

      }); 

おかげで、すべて。我々はアヤックスのため

var currentLatLng = position.coords; 
       var Lat = currentLatLng.latitude; 
       var Lng = currentLatLng.longitude; 
       var LatDouble = parseFloat(Lat); 
       var LngDouble = parseFloat(Lng); 

を倍増するLNG & LANTを変換する必要が

答えて

0

はATT

data: JSON({ CurrentLng:LngDouble , CurrentLat: LatDouble }), 
を文字列化削除することです
関連する問題