Question

I'm trying to track specific smartphones for a cab company using jQuery Mobile. What would be the easiest way to go about this? I've heard good things about Google Latitude, but it's still a little tricky. Is there a way to "plug in" to specific smartphones? (With permission from its owner of course.)

Était-ce utile?

La solution

You'll find HTML GeoLocation to be much easier to implement, but troublesome for tracking more than a few minutes at a time. Google Latitude is the easiest way to constantly track Android or iOS devices, as the client-side work is done for you and you need only figure out how to ask Google correctly from your server. I have done it a few times on Rails with the Omniauth gem. Here are some snippets that may speed things along for you even if you don't use that particular library:

Omniauth.rb line dictating which permissions are required:

provider :google_oauth2, GOOGLE_KEY, GOOGLE_SECRET, { access_type: "offline", approval_prompt: "", scope: "https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/latitude.current.best" }

Elsewhere, calling for latitude given the access token:

latitude_data = HTTParty.get('https://www.googleapis.com/latitude/v1/currentLocation?granularity=best&access_token='+self.access_token)['data']

Another thing that will take some time is setting up a background task that exchanges the long-term "refresh" token for a new access token once per hour. This is needed for Latitude because of extra security concerns. You'll find that the refresh token is only sent on the first time your app is authorized, and that subsequently it's necessary to deauthorize the application at accounts.google.com and reauthorize to get a refresh token. I think there's an easier way involving an extra parameter when authorizing that forces reauth, but I haven't used it yet.

Good luck! Latitude is my favorite API, a great tool in the new geo-aware internet! For more examples of both Geolocation API and Latitude, check out my project using both at github.com/nelsonblaha/groovitation

Autres conseils

Yep, using the HTML5 GeoLocation API. The user will be prompted for their permission, but then you can watch:

var watchID = navigator.geolocation.watchPosition(function(position) {
  do_something(position.coords.latitude, position.coords.longitude);
});

https://developer.mozilla.org/en-US/docs/WebAPI/Using_geolocation

You need to thing this through, are you creating this app for small number of drivers or a large number.

  • This is way is it important to choose a proper js framework. Phonegap will be a wrapper of course. Top combination for a real time java script client / server communication architecture is a Node.js and SOCKET.IO framework. Unfortunately they are useful only in a clean hybrid app (app built without some js mobile app framework like jQuery Mobile, jQMoby ....).

If you are going to use a js mobile app framework you will need to use it in combination with backbone js framework. Not nearly good as node.js and socket IO but still a good combination. Node.js and socket IO don't play well with other js mobile app frameworks.

  • Use phonegap geolocation API to acquire a car lat and lng position. Unlike sport GPS applications you don't need to refresh every second. Cars are going through the predefined routs so 30 sec refresh time will be enough.

  • Don't tie 30 sec interval to the real time (11:00:00, 11:00:30, 11:01:00 ...) because every single device will try to send a location refresh at the same time and that will kill a server infrastructure. It is better to time it every 30 sec after app is initialized.

  • Driver's device app could be a small app. It will work as a background process. Because data will be sent every 30 sec net traffic and batter life want be a real problem.

  • Requester device will get a bulk data (every possible car in some radius around requester device) every predefined time. Before server can send bulk data requester must send its location. It will be used to get nearest cars.

  • Google Maps mobile API v3 will be used as a map at a requester device. Because this is a mobile device and mobile frameworks are not know for they excellent performances, don't use it do display more then 100 cars (few hundred at best in case of desktop web app).

  • My final advice is, if possible create a native mobile app, because hybrid mobile apps are not that good at handling real time data. At lease not a large amount of data. Stick with a longer transition interval, it will save your battery. And don't think of using a XML as a client/server data. It has a large data overhead.

Node.js

Socket.IO

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top