Question

I am setting up a website that shows a Google map and the location of various Google Latitude users on that map via markers.

Thing is, I can't find the exact code to do that. I have trawled through the Google API docs which are extensive but lacking in examples, actual examples of how a finished page might look.

So, I have my Google Map in place and I have registered an account on the Google API and set up OAUTH2 (got my clientID etc.) but I am stuck as to what to do next.

Any suggestions much appreciated.

Était-ce utile?

La solution

The Latitude API documentation will tell you all the specific things it can do. It won't do general things for you like "put markers on a Google map"- it is meant to be used rather separately from Maps API. Your application will have to get Latitude oauth authorization for each of the users and use access tokens to request their locations. Only then will you start using Maps API to plot markers of those locations.

It sounds like you have no prior knowledge of any particular framework, so I'll outline how I would do it with Rails, which I believe to be easiest:

  • Build Omniauth into a new application, so that the user can sign in with Google. There are tutorials to assist you. The sign-in will result in an access token being stored in your database.

  • Add the latitude 'scope' to your omniauth implementation. The scope can be found in the latitude documentation, and the syntax to add it is found in the omniauth documentation.

  • For security reasons peculiar to latitude, you'll have to store the 'refresh token' that's supplied only on the first google sign-in for each user and exchange it hourly for a new access token as explained in the google oauth documentation.

  • Once you have a valid access token for each user at all times, you can use a library such as HTTParty to complete the GET described in the latitude documentation and retrieve a location.

  • Build a Google Map into a rails view as described in the Maps API documentation. In the controller action that processes that view, you can pass in the user locations for use as markers.

Good luck.

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