0

I need to load pins to a map (Google Maps Android API v2) as the user changes its location, but I wanted to load them "smoothly" instead of having to wait for the entire result set being downloaded to add all pins at once.

Is there any web service or a different technology that allows me to read data (like JSON) from the server as a stream and asynchronously add pins to the map?

Thanks.

juliano.net
  • 7,982
  • 13
  • 70
  • 164
  • I'm assuming you're in control of the server? If that is so, why not simply use `Transfer-Encoding: chunked` and write out pieces of JSON? – Nitzan Shaked Sep 23 '13 at 15:50
  • @NitzanShaked as this [link](http://stackoverflow.com/questions/16736233/web-api-as-a-proxy-and-chunked-transfer-encoding) points, the HttpClient will de-chunk the message, thus it will wait for the entire response to be processed so it can add pins to the map. – juliano.net Sep 23 '13 at 16:04
  • @JulianoNunesSilvaOliveira: that's a detail of a specific HTTP client. Doesn't your client (on android presumably) have an `onData()` or `bufferReceived` event? – Nitzan Shaked Sep 23 '13 at 16:07
  • I found that Volley http library has an `onResponse` event. I'll try it when I get home. Thanks – juliano.net Sep 23 '13 at 16:16

2 Answers2

0

I can think of two ways of approaching this for asynchronously loading google points

  1. Using Services and Broadcasts, Using an IntentService (or a Service class) to parse the JSON and broadcasting the results as and when you get results in your parsing. Have a Broadcast Receiver which would be listening to these broadcasts. In the onHandle method of your broadcast receiver you could keep creating new markers. (Tutorial)

  2. Using AsyncTask and on your onProgressUpdate method you could keep passing your json parse results and that could keep updating the maps.

As for parsing of JSON I believe you can just use any parsing techniques to get an input stream.

I think I would suggest the first approach as that would be more fluid and gives you more control if you are using multi-threading.

Hope this helps

Guru
  • 916
  • 3
  • 12
  • 22
0

Oboe.js is a tool for reading of JSON as it arrives. Other projects have used it to load a lot of points into a Google map but show them one at a time.

disclaimer: it is my project.

jimhigson
  • 192
  • 2
  • 4