Leaflet Client GPS Location

302 views
Skip to first unread message

Tracy Wolf

unread,
Sep 3, 2013, 10:05:57 PM9/3/13
to opentripp...@googlegroups.com
Hello,

I am currently working on my own instance of the leaflet client and am trying to set the leaflet client up to initially zoom into the user's current location. I'm curious as to whether this is possible and if it is how I can go about doing it. I've tried all sorts of different things and have been able to get the users current location but don't know how to set that to the initial latitude and longitude on loading the webpage.

Any help would be greatly appreciated.


Thanks,
Tracy.

David Emory

unread,
Sep 4, 2013, 11:14:33 AM9/4/13
to Tracy Wolf, opentripp...@googlegroups.com
Hi Tracy,

Currently the main way to set a custom start position for the leaflet client is using the otp.config.initLatLng configuration property, which can be specified in config.js. The value is an instance of Leaflet's L.LatLng class. The default config.js file includes a commented-out example of this at line 54: https://github.com/openplans/OpenTripPlanner/blob/master/otp-leaflet-client/src/main/webapp/js/otp/config.js

I've never set up the client to use a dynamic start location, but there are a couple ways you might try doing this:

- dynamically generate config.js to include the desired initLatLng prior to loading the client

- if you are modifying the core client code, you could set otp.config.initLatLng programatically. This could be done in the initialize() method of otp.core.Webapp (just make sure it's done before otp.core.Map is initialized)

Just curious, what are you using for geolocation? I've never played around with it, but Leaflet's L.Map object does have a built-in locate() method that is supposed to work on most modern browsers. If you're OK using that, it would be simple enough to add a new otp.config property (e.g. 'enableGeolocation') that would tell the client to try that first, falling back on otp.config.initLatLng or the OTP graph metadata as needed.

DDE



--
You received this message because you are subscribed to the Google Groups "OpenTripPlanner Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to opentripplanner...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Jeff Lyon

unread,
Sep 15, 2013, 1:40:33 PM9/15/13
to opentripp...@googlegroups.com, Tracy Wolf
I have used the Leaflet locate() method before in other projects and it works well.

Jeff
To unsubscribe from this group and stop receiving emails from it, send an email to opentripplanner-dev+unsub...@googlegroups.com.

Tracy Wolf

unread,
Sep 16, 2013, 5:55:30 PM9/16/13
to opentripp...@googlegroups.com, Tracy Wolf
Hey,

I did get this working a couple weeks ago with the locate() function. 

Thanks for the help. :)
Reply all
Reply to author
Forward
0 new messages