Tweet as you go to different neighbourhoods of Montreal (you can change to your city + locations)

Fire a tweet w/ a map location of where you are when you get into a different neighbourhood: downtown, Plateau, Mont-Royal, Old Port, etc.

Save Recipe

This recipe uses tweetonX, so you will need to get a token there so you can tweet from your account.

Twitter Config

Update your Twitter configurations:

var twitter = { screenName : "tweetonx", onxToken : "6tblahblah" } ;

Locations

You might want to change your neighbourhoods too.

Change the name, lat, long:

var downtown = { name : "downtown",latitude : "45.500696",longitude : "-73.568578" } ;

Be sure to change the (1) region variable definition,  (2) the tweet definition when entering the region, and (3) the start monitoring call for each region you change the name, add, remove.

To use this on{X} Recipe, simply copy the code below and modify if needed.

    // Initializing variables 

    var downtown = { name : "downtown",latitude : "45.500696",longitude : "-73.568578" } ;
    var montRoyal = { name : "at Mount Royal",latitude : "45.505674",longitude : "-73.589751" } ;
    var plateau = { name : "in the Plateau",latitude : "45.51626",longitude : "-73.576769" } ;
    var oldPort = { name : "in Old Port",latitude : "45.507508",longitude : "-73.553885" } ;
    var atWater = { name : "in AtWater",latitude : "45.485504",longitude : "-73.570847" } ;
    var canalLachine = { name : "at Canal LaChine",latitude : "45.488257",longitude : "-73.56015" } ;
    
    var twitter = { screenName : "tweetonx", onxToken : "6tblahblah" } ;
    var mapUrlPattern = 'http://maps.google.com/maps?z=1&t=m&q=loc:lat+lon';

    // create a geo region for the trigger to take place at
    var regionDowntown = device.regions.createRegion({
        latitude: parseFloat(downtown.latitude, 10),
        longitude: parseFloat(downtown.longitude, 10),
        name: downtown.name,
        radius: 600
    });
    
    var regionMontRoyal = device.regions.createRegion({
        latitude: parseFloat(montRoyal.latitude, 10),
        longitude: parseFloat(montRoyal.longitude, 10),
        name: montRoyal.name,
        radius: 600
    });
    
    var regionPlateau = device.regions.createRegion({
        latitude: parseFloat(plateau.latitude, 10),
        longitude: parseFloat(plateau.longitude, 10),
        name: plateau.name,
        radius: 600
    });
    
    var regionOldPort = device.regions.createRegion({
        latitude: parseFloat(oldPort.latitude, 10),
        longitude: parseFloat(oldPort.longitude, 10),
        name: oldPort.name,
        radius: 600
    });
    
    var regionAtWater = device.regions.createRegion({
        latitude: parseFloat(atWater.latitude, 10),
        longitude: parseFloat(atWater.longitude, 10),
        name: atWater.name,
        radius: 600
    });
    
    var regionCanalLachine = device.regions.createRegion({
        latitude: parseFloat(canalLachine.latitude, 10),
        longitude: parseFloat(canalLachine.longitude, 10),
        name: canalLachine.name,
        radius: 600
    });

    // tweet when enter a neighborhood
    regionDowntown.on('enter', function () {
        var listener = device.location.createListener('GPS', 5000); 

        // regiter on location changed
        listener.on('changed', function (signal) {
            var mapUrl =  mapUrlPattern.replace(/lat/g, signal.location.latitude).replace(/lon/g, signal.location.longitude);      
            var tweet = encodeURI('I am ' + regionDowntown.name + ' @ ' + mapUrl);
            listener.stop();
            
            // Sends tweet using TweetOn{X}
            device.ajax(
                {
                    url: 'http://tweetonx.com/api/tweet/'+twitter.screenName+'/'+twitter.onxToken+'/?t='+tweet,
                    type: 'GET',
                    headers: { 'Content-Type': 'application/xml' }
                },
                function onSuccess(body, textStatus, response){
                    var parsedBody;
                    if(!body){
                        var error = {};
                        error.message = 'invalid body format';
                        error.content = body;
                        console.error('error: ',error);
                    }
                    var notification = device.notifications.createNotification('Status: ' + regionDowntown.name + ' -- ' + body);
                    notification.show();
                    console.info('Status: ' + body);
                },
                function onError(textStatus, response){
                    var error = {};
                    error.message = textStatus;
                    error.statusCode = response.status;
                    console.error('error: ',error);
                }
            ); 
        });    
    });
    
    regionMontRoyal.on('enter', function () {
        var listener = device.location.createListener('GPS', 5000); 

        // regiter on location changed
        listener.on('changed', function (signal) {
            var mapUrl =  mapUrlPattern.replace(/lat/g, signal.location.latitude).replace(/lon/g, signal.location.longitude);      
            var tweet = encodeURI('I am ' + regionMontRoyal.name + ' @ ' + mapUrl);
            listener.stop();
            
            // Sends tweet using TweetOn{X}
            device.ajax(
                {
                    url: 'http://tweetonx.com/api/tweet/'+twitter.screenName+'/'+twitter.onxToken+'/?t='+tweet,
                    type: 'GET',
                    headers: { 'Content-Type': 'application/xml' }
                },
                function onSuccess(body, textStatus, response){
                    var parsedBody;
                    if(!body){
                        var error = {};
                        error.message = 'invalid body format';
                        error.content = body;
                        console.error('error: ',error);
                    }
                    var notification = device.notifications.createNotification('Status: ' + regionMontRoyal.name + ' -- ' + body);
                    notification.show();
                    console.info('Status: ' + body);
                },
                function onError(textStatus, response){
                    var error = {};
                    error.message = textStatus;
                    error.statusCode = response.status;
                    console.error('error: ',error);
                }
            );
        });
    });
    
    regionPlateau.on('enter', function () {
        var listener = device.location.createListener('GPS', 5000); 

        // regiter on location changed
        listener.on('changed', function (signal) {
            var mapUrl =  mapUrlPattern.replace(/lat/g, signal.location.latitude).replace(/lon/g, signal.location.longitude);      
            var tweet = encodeURI('I am ' + regionPlateau.name + ' @ ' + mapUrl);
            listener.stop();

            // Sends tweet using TweetOn{X}
            device.ajax(
                {
                    url: 'http://tweetonx.com/api/tweet/'+twitter.screenName+'/'+twitter.onxToken+'/?t='+tweet,
                    type: 'GET',
                    headers: { 'Content-Type': 'application/xml' }
                },
                function onSuccess(body, textStatus, response){
                    var parsedBody;
                    if(!body){
                        var error = {};
                        error.message = 'invalid body format';
                        error.content = body;
                        console.error('error: ',error);
                    }
                    var notification = device.notifications.createNotification('Status: ' + regionPlateau.name + ' -- ' + body);
                    notification.show();
                    console.info('Status: ' + body);
                },
                function onError(textStatus, response){
                    var error = {};
                    error.message = textStatus;
                    error.statusCode = response.status;
                    console.error('error: ',error);
                }
            );
        });
    });
    
    regionOldPort.on('enter', function () {
        var listener = device.location.createListener('GPS', 5000); 

        // regiter on location changed
        listener.on('changed', function (signal) {
            var mapUrl =  mapUrlPattern.replace(/lat/g, signal.location.latitude).replace(/lon/g, signal.location.longitude);      
            var tweet = encodeURI('I am ' + regionOldPort.name + ' @ ' + mapUrl);
            listener.stop();
    
            // Sends tweet using TweetOn{X}
            device.ajax(
                {
                    url: 'http://tweetonx.com/api/tweet/'+twitter.screenName+'/'+twitter.onxToken+'/?t='+tweet,
                    type: 'GET',
                    headers: { 'Content-Type': 'application/xml' }
                },
                function onSuccess(body, textStatus, response){
                    var parsedBody;
                    if(!body){
                        var error = {};
                        error.message = 'invalid body format';
                        error.content = body;
                        console.error('error: ',error);
                    }
                    var notification = device.notifications.createNotification('Status: ' + regionOldPort.name + ' -- ' + body);
                    notification.show();
                    console.info('Status: ' + body);
                },
                function onError(textStatus, response){
                    var error = {};
                    error.message = textStatus;
                    error.statusCode = response.status;
                    console.error('error: ',error);
                }
            );
        });
    });
    
    regionAtWater.on('enter', function () {
        var listener = device.location.createListener('GPS', 5000); 

        // regiter on location changed
        listener.on('changed', function (signal) {
            var mapUrl =  mapUrlPattern.replace(/lat/g, signal.location.latitude).replace(/lon/g, signal.location.longitude);      
            var tweet = encodeURI('I am ' + regionAtWater.name + ' @ ' + mapUrl);
            listener.stop();
    
            // Sends tweet using TweetOn{X}
            device.ajax(
                {
                    url: 'http://tweetonx.com/api/tweet/'+twitter.screenName+'/'+twitter.onxToken+'/?t='+tweet,
                    type: 'GET',
                    headers: { 'Content-Type': 'application/xml' }
                },
                function onSuccess(body, textStatus, response){
                    var parsedBody;
                    if(!body){
                        var error = {};
                        error.message = 'invalid body format';
                        error.content = body;
                        console.error('error: ',error);
                    }
                    var notification = device.notifications.createNotification('Status: ' + regionAtWater.name + ' -- ' + body);
                    notification.show();
                    console.info('Status: ' + body);
                },
                function onError(textStatus, response){
                    var error = {};
                    error.message = textStatus;
                    error.statusCode = response.status;
                    console.error('error: ',error);
                }
            );
        });
    });
    
    regionCanalLachine.on('enter', function () {
        var listener = device.location.createListener('GPS', 5000); 

        // regiter on location changed
        listener.on('changed', function (signal) {
            var mapUrl =  mapUrlPattern.replace(/lat/g, signal.location.latitude).replace(/lon/g, signal.location.longitude);      
            var tweet = encodeURI('I am ' + regionCanalLachine.name + ' @ ' + mapUrl);
            listener.stop();
    
            // Sends tweet using TweetOn{X}
            device.ajax(
                {
                    url: 'http://tweetonx.com/api/tweet/'+twitter.screenName+'/'+twitter.onxToken+'/?t='+tweet,
                    type: 'GET',
                    headers: { 'Content-Type': 'application/xml' }
                },
                function onSuccess(body, textStatus, response){
                    var parsedBody;
                    if(!body){
                        var error = {};
                        error.message = 'invalid body format';
                        error.content = body;
                        console.error('error: ',error);
                    }
                    var notification = device.notifications.createNotification('Status: ' + regionCanalLachine.name + ' -- ' + body);
                    notification.show();
                    console.info('Status: ' + body);
                },
                function onError(textStatus, response){
                    var error = {};
                    error.message = textStatus;
                    error.statusCode = response.status;
                    console.error('error: ',error);
                }
            );
        });
    });

    // start monitoring the region
    device.regions.startMonitoring(regionDowntown);
    device.regions.startMonitoring(regionMontRoyal);
    device.regions.startMonitoring(regionPlateau);
    device.regions.startMonitoring(regionOldPort);
    device.regions.startMonitoring(regionAtWater);
    device.regions.startMonitoring(regionCanalLachine);
    

Recipe Wall

875

Views