I've seen the demo of auto tracking (when clicking simulate) http://openlayers.org/en/v3.2.1/examples/geolocation-orientation.html and tried to copy it.

and I want to modify the code and place the marker on different places on the screen (in the center for example).

I know the "magic" is done in this function :

var getCenterWithHeading = function (position, rotation, resolution) {
var size = map.getSize();
var height = size[1];

return [
    position[0] - Math.sin(rotation) * height * resolution * 1 / 4,
    position[1] + Math.cos(rotation) * height * resolution * 1 / 4


But I don't understand how to modify it so the marker will be in the center of the map.

1 Answer 1


Just use the marker position as center:

return [
  • But if I change the position than the location of the marker is not correct according to the GPS coordinates it record (the location on the map) , which means that the map itself is not moving to the correct place
    – Alophind
    Jun 9, 2015 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.