سؤال

I want to make a compass in the browser (mobile website, NOT native applicaton). The purpose is that you have a button "Save current location to localstorage" and when you click on that button you save the latitude & longitude of the current location in the localstorage of the browser.

Then later when you are for example one kilometre from the location saved in the localstorage (for example on a parking) that you have a compass with an arrow headed to the location in your localstorage.

What I do now is save the location in the localstorage. But I don't now how I can make a compass headed to the location?

This is what I do now:

enter image description here

Can somebody help me?

Thanks in advance!

Now I also have the direction of my phone.

هل كانت مفيدة؟

المحلول

You have 2 points (x1,y1) and (x2,y2). Angle between those 2 points in js is:

var angle = Math.atan2(y2 - y1, x2 - x1);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top