I’m just wondering is it feasible to ask Android from web browser(any computer) to give its location(example) so that user can view it using google maps.
Here is the design I have on my head:
- From browser send request to get location to web server
- Add one record to DB table(GCM_REQUESTS) with request and time
requested. - Web server send request to give location( or whatever) using GCM
along with requestId. - GCM will send same data to android
- Now Android app parses the data(request) and sends it location
something like this
(http://myserver.com/updatelocation?reqId=123&lon=10.0&lat=5.5) - This will be be persisted in GCM_REQUESTS table.
- In the mean time using AJAX calls we pool(5 secs) for any updates in
GCM_REQUESTS table, if we find any update we will read it and send it
back to browser - Now AJAX calls will stop polling and browser will be updated with
location.
Please guide me whether this approach is efficient, can it be optimized by following any other method.
I have done something similar, This method works perfectly for me, here are just a few helpful pointers:
1) When you do the push to the GCM server, if the response is not successful (for example, NotRegistered or MisMatchSenderID) then respond to the user via the browser appropriately (the application is no longer installed on the device or there was an error communicating with the device)
2) If the device responds with null make sure this is handled (see below) and reported to the user in a manner like the devices location could not be determined at this point in time.
Something I encountered that crashed allot of my apps is if you try set the locational data into the post and it is null. I have pasted my code below to handle this so you can avoid such a problem.
Hope this helps