Reputation: 6855
I am using asp.net mvc. This Project is a map based Project. I have an action method that returns big json data.
public JsonResult MemberLocations()
{
var members = memberRepository.GetAll();
var result = new { members };
var jsonresult = Json(result, JsonRequestBehavior.AllowGet);
jsonresult.MaxJsonLength = 500000000;
return jsonresult;
}
This method returns members locations.
[{memberX:"132.45", memberY:"212.21"}, {memberX:"112.45", memberY:"113.11"},........]
The json data has 45.000 point (x,y) pairs. I am getting this points an adding pin on the map. The query result is coming very late. (I am using javascript ajax request. )
How can I solve the data getting mechanism. Have you solved a problem like this?
Upvotes: 0
Views: 1723
Reputation: 13380
First you should check if it is really the transfer of 45k points which slows down the application or if it is your data retrieval. Just use stopwatch around the call of memberRepository.GetAll();
and measure the time of the response in fiddler to evaluate how much % of the time it takes to retrieve the data...
Usually you should really not send so much data to the client. It usually results in bad user experience, especially on slower devices (mobile...).
Maybe you have to ask yourself why do you have to send 45k coordinates to the client?
Are you showing all the pins on the map at once? Really? If not, send only those which should be displayed for the zoom level/view port...
If you still need to render that much data, use other techniques to render it, e.g. rendering tiles on the server.
Another option for lots of LatLong coordinates is to encode the data, which will reduce the size. This can be achieved with this google algorithm for example
Upvotes: 0
Reputation: 2681
You need to profile this function for performance, which part of this taking more time. Sending array of JSON object of size 45 would not take more time. It seems it may be taking more time in getting the data "memberRepository.GetAll()".
Upvotes: 1