Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Using the Geolocation API in JavaScript

Melissa Kepler
Melissa Kepler
11,369 Points

getCurrentPosition() and watchPosition() are deprecated according to chorme security.

I just wanted to put it out there in case anyone else runs sees this in their Chrome console while doing this workshop. I had no problems with the code, but I got this warning:

"getCurrentPosition() and watchPosition() are deprecated on insecure origins, and support will be removed in the future. You should consider switching your application to a secure origin, such as HTTPS. See https://goo.gl/rStTGz for more details."

Andrew Chalkley, does this mean in the future people doing this workshop will not be able to check their code through their browser?

3 Answers

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

All the code will work but on https sites. I have no idea what the implications are about running it locally though :/

You're right. Your accent take time to understand, but you are a good teacher and i hope more javascript courses made by you.

Mike Gentry
seal-mask
.a{fill-rule:evenodd;}techdegree
Mike Gentry
Full Stack JavaScript Techdegree Student 4,296 Points

How is this a helpful response? I am getting the same error too. Looks like the workspace/workshop is broken and needs updating.

Andrew Chalkley
Andrew Chalkley
Treehouse Guest Teacher

When I click on preview in workspaces, the url is an http:// url. When I change it to https:// it works.

For example, my workspace preview url started as:

http://port-80-x9889ymuhb.treehouse-app.com/

...when I modified the URL to be secure, with https in front it now works.

https://port-80-x9889ymuhb.treehouse-app.com/

Chrome's policy only allows Geolocation on secure URLs now.

For anyone who wants to follow along, use the NPM package Browser Sync: https://www.npmjs.com/package/browser-sync

Once you have it installed, run browser-sync start --server --https and you'll have a local HTTPS server.

Many APIs require HTTPS, so I've been using Browser Sync for all my work outside of Treehouse. To get around the Cross Origin Resource Sharing limitation on many APIs, you can add the --cors flag when running Browser Sync as well.

There are other local dev server programs - I just personally think Browser Sync is the best :)

Daniel Murnane
Daniel Murnane
5,079 Points

Doesn't seem to have been much discussion on this in a while, but I have another option that lets you learn a bit about the Google geolocation along the way! I followed this StackOverflow answer.

Follow the JSfiddle example given in the top answer, and it requires only a little alteration to the Treehouse workspace. The main alterations are:

  1. Add a "failed" argument to the main function: js navigator.geolocation.getCurrentPosition(gotLocation,browserGeolocationFail,{maximumAge: 50000, timeout: 20000, enableHighAccuracy: true});
  2. Copy the chunk inside gotLocation(){...} into apiGeolocationSuccess(){...}
  3. Fix the position/currentPosition inconsistency between the workspace and the StackOverflow answer

Bingo! It should work.