Foren

Saving HTML5 Geolocation Data into Portal Session Variables

lsli lsli, geändert vor 9 Jahren.

Saving HTML5 Geolocation Data into Portal Session Variables

Junior Member Beiträge: 62 Beitrittsdatum: 11.11.08 Neueste Beiträge
I am currently using Liferay 6.0.6 (and cannot upgrade for now) and want users to to be able to specify their location using HTML5 geolocation:

http://www.w3schools.com/html/html5_geolocation.asp
http://dev.w3.org/geo/api/spec-source.html

I just want to get a person's latitude and longitude coordinates when the user is prompted by the browser to ask for his or her location, e.g.:

http://html5demos.com/geo

Yes, I understand that I could get a user's approximate location using some of these IP geolocation techniques, but these aren't as accurate and if one is using a cell phone, I could get the user's precise location as well using HTML5 geolocation. I'm mostly interested in latitude and longitude, though I wouldn't object if I could get all the properties from the Geolocation object.

I only want to ask for the user's location once in a session when the user first accesses any page on my site. If the person declines to provide their location, I do not want to ask the user again for their location even if they visit other pages on my site (so the person does not get ignored) unless the session expires. Ultimately, if a user does provide their location, I was the Geolocation object properties (at least latitude and longitude) passed to Liferay and made available as a portal session object - which in turn would be readable by other portlets.

How would I do something like this? I know how to grab the Geolocation info from the user using the first link, but how do I pass this back to Liferay when the user accepts the location request (or pass back the user declining the request)? I'm guessing there's some JS I can write to accomplish this...? And how would I set this to a portal session object? Is there any change I have to make to any Liferay configuration files?

Also, how would I want to implement the Javascript code? Should I place the Javascript that does all of the above into a page template or is it advised to put it into a hook?

https://www.liferay.com/community/forums/-/message_boards/message/13723996
lsli lsli, geändert vor 9 Jahren.

RE: Saving HTML5 Geolocation Data into Portal Session Variables

Junior Member Beiträge: 62 Beitrittsdatum: 11.11.08 Neueste Beiträge
Can anyone provide any help? I would really appreciate it as this is a blocker for me. Thanks!
thumbnail
David H Nebinger, geändert vor 9 Jahren.

RE: Saving HTML5 Geolocation Data into Portal Session Variables

Liferay Legend Beiträge: 14919 Beitrittsdatum: 02.09.06 Neueste Beiträge
There's nothing magical to it, in fact the geo demo probably has all of the code that you need to implement it.

As far as how to pass to the server, well you can encode them as parameters on either an action or resource request. On the server side you pluck them out of the request and push to the session.

Easy peasy.
lsli lsli, geändert vor 9 Jahren.

RE: Saving HTML5 Geolocation Data into Portal Session Variables

Junior Member Beiträge: 62 Beitrittsdatum: 11.11.08 Neueste Beiträge
Hi David, thanks for the info.

I'm quite weak on the Liferay Javascript stuff. I'm guessing that I should create a new Liferay service that is passed the latitude and longitude from the browser - and I would make a Javascript call (with the latitude and longitude info) to invoke this Liferay service? I've been avoiding a lot of the Liferay Javascript stuff for quite a while... Is there any URL that describes what I need to do? Would I use AUI Ajax calls to do this? How do I call a Liferay service from Javascript, JQuery, or AUI? Again, I admit I have a severe lack of knowledge on the client side Liferay stuff... Any suggestions on documentation that describes in general how this needs to be done?
thumbnail
David H Nebinger, geändert vor 9 Jahren.

RE: Saving HTML5 Geolocation Data into Portal Session Variables

Liferay Legend Beiträge: 14919 Beitrittsdatum: 02.09.06 Neueste Beiträge
I think you're muddying the waters here...

The demo site leverages ajax and javascript to access the lat/long, submit request to server and display the map. You could pretty much leverage that code practically line by line.

For the portal perspective, at the end of the day you're submitting the lat/long plus whatever fields the user has populated to the server side for storage.

That's why I said no magic and no complications. You use what they give you, store the lat/long on hidden input fields using javascript so they'll get back to the server on form submit, and boom you're done.

There's no need to complicate things turning that map stuff into a liferay service fronted by AUI or whatever, it's already done so why rewrite it?
thumbnail
Salva Tejero, geändert vor 8 Jahren.

RE: Saving HTML5 Geolocation Data into Portal Session Variables

Junior Member Beiträge: 77 Beitrittsdatum: 13.06.11 Neueste Beiträge
In this repository https://github.com/salvatejero/liferay-geolocation-portlet
I have stored a plugin and a hook to store location and Search content using this location. I hope you can use it

I want to add Audience integration