New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPS and compass data would be sweet. #250

Closed
jessemillar opened this Issue Nov 13, 2013 · 4 comments

Comments

Projects
None yet
3 participants
@jessemillar

jessemillar commented Nov 13, 2013

I've got a couple of game ideas in mind that mandate GPS and compass data. I tried throwing some prototypes together in Phonegap but it just wasn't cutting it. Whenever you find the time to add some calls to the geolocation API to Ejecta I would be eternally grateful and probably draw you a picture of a puppy.

@phoboslab phoboslab closed this in d661558 Nov 20, 2013

@phoboslab

This comment has been minimized.

Show comment
Hide comment
@phoboslab

phoboslab Nov 20, 2013

Owner
var success = function(position) {
    console.log('position', JSON.stringify(position.coords), position.timestamp);
};
var error = function(error) {
    if( error.code === navigator.geolocation.PERMISSION_DENIED ) {
        // Remember that we don't have permissions and don't try again
    }
    console.log('error', error.code, error.message);
}

// One shot location - aims to return fast and may be imprecise.
// Set enableHighAccuracy to true for better results
navigator.geolocation.getCurrentPosition(success, error, {enableHighAccuracy:false});




// Draw line of continuos movement on canvas
var ctx = canvas.getContext('2d');
ctx.strokeStyle = '#f0f';
var first = true;
var coords = [];

var cx = canvas.width/2,
    cy = canvas.height/2;


var draw = function(position) {
    // clear
    ctx.fillStyle = '#000000';
    ctx.fillRect(0,0,canvas.width,canvas.height);

    // show coords
    ctx.fillStyle = '#ffffff';
    ctx.fillText( position.coords.latitude, 8, 16 );
    ctx.fillText( position.coords.longitude, 8, 32 );


    // collect coords but limit to 500
    coords.push( position.coords );
    if( coords.length > 500 ) {
        coords.shift();
    }

    // draw path
    ctx.beginPath();

    var first = coords[0]; // take first coords as center
    for( var i = 0; i < coords.length; i++ ) {
        var x = first.longitude - coords[i].longitude,
            y = first.latitude - coords[i].latitude;
        ctx.lineTo(cx + x * 10000, cy + y * 10000);
    }

    ctx.stroke();
};

// Continuously watch location; will always enable high accuracy
var watchId = navigator.geolocation.watchPosition(draw, error);

// Stop watching for position changes
// navigator.geolocation.clearWatch( watchId );
Owner

phoboslab commented Nov 20, 2013

var success = function(position) {
    console.log('position', JSON.stringify(position.coords), position.timestamp);
};
var error = function(error) {
    if( error.code === navigator.geolocation.PERMISSION_DENIED ) {
        // Remember that we don't have permissions and don't try again
    }
    console.log('error', error.code, error.message);
}

// One shot location - aims to return fast and may be imprecise.
// Set enableHighAccuracy to true for better results
navigator.geolocation.getCurrentPosition(success, error, {enableHighAccuracy:false});




// Draw line of continuos movement on canvas
var ctx = canvas.getContext('2d');
ctx.strokeStyle = '#f0f';
var first = true;
var coords = [];

var cx = canvas.width/2,
    cy = canvas.height/2;


var draw = function(position) {
    // clear
    ctx.fillStyle = '#000000';
    ctx.fillRect(0,0,canvas.width,canvas.height);

    // show coords
    ctx.fillStyle = '#ffffff';
    ctx.fillText( position.coords.latitude, 8, 16 );
    ctx.fillText( position.coords.longitude, 8, 32 );


    // collect coords but limit to 500
    coords.push( position.coords );
    if( coords.length > 500 ) {
        coords.shift();
    }

    // draw path
    ctx.beginPath();

    var first = coords[0]; // take first coords as center
    for( var i = 0; i < coords.length; i++ ) {
        var x = first.longitude - coords[i].longitude,
            y = first.latitude - coords[i].latitude;
        ctx.lineTo(cx + x * 10000, cy + y * 10000);
    }

    ctx.stroke();
};

// Continuously watch location; will always enable high accuracy
var watchId = navigator.geolocation.watchPosition(draw, error);

// Stop watching for position changes
// navigator.geolocation.clearWatch( watchId );
@jessemillar

This comment has been minimized.

Show comment
Hide comment
@jessemillar

jessemillar Nov 20, 2013

You, sir, are a hero.

jessemillar commented Nov 20, 2013

You, sir, are a hero.

@Incubatio

This comment has been minimized.

Show comment
Hide comment
@Incubatio

Incubatio Nov 20, 2013

puppy picture pls.

Incubatio commented Nov 20, 2013

puppy picture pls.

@jessemillar

This comment has been minimized.

Show comment
Hide comment
@jessemillar

jessemillar Dec 9, 2013

screen shot 2013-12-09 at 9 42 17 am

(Nabbed a puppy drawing from one of my other projects.)

Any chance of adding the ability to monitor the current compass heading?

UPDATE
Created an issue for the compass data here: #258

jessemillar commented Dec 9, 2013

screen shot 2013-12-09 at 9 42 17 am

(Nabbed a puppy drawing from one of my other projects.)

Any chance of adding the ability to monitor the current compass heading?

UPDATE
Created an issue for the compass data here: #258

@phoboslab phoboslab referenced this issue Dec 21, 2013

Closed

Compass Data? #258

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment