Realtime geolocation tracking via realtime service provider - laravel

I want to make a map marker which will move whenever it gets updates from server. Each map marker is described by a latitude and longitude.
var url = '/tracking/records/fetch'+ '&id=' + user_id +'&type='+type;
This endpoint returns a set of latitude,longitude in JSON format.
How to move the marker when browser get updates from server ?

It sounds like your /tracking/records/fetch endpoint is set up for polling: your webpage can repeatedly fetch a whole set of coordinates from the server, then update a map view of those coordinates. To make this realtime, you need to move away from pure polling to pushing.
First, sign up for a Pusher account. Then have your webpage connect to your Pusher app and subscribe to a channel for new coordinates:
<script src="//js.pusher.com/4.0/pusher.min.js"></script>
<script>
var pusher = new Pusher('YOUR_APP_KEY', {
cluster: 'YOUR_APP_CLUSTER'
});
var tracking-records = pusher.subscribe('tracking-records-' + type + '-' + user_id); // Channel specific to this user
tracking-records.bind('new-tracking-record', function(data) {
console.log('A new tracking record with latitude', data.latitude, 'and longitude', data.longitude);
// Update your Google Map view here using data.latitude, data.longitude
});
</script>
Then on your server, identify where the tracking records are created (probably a database insert). At that point, publish the new coordinate to the tracking-records channel. Here's an example in Node.js:
var Pusher = require('pusher');
var pusher = new Pusher({
appId: 'APP_ID',
key: 'APP_KEY',
secret: 'APP_SECRET',
cluster: 'APP_CLUSTER'
});
pusher.trigger(
'tracking-records-' + type + '-' + user_id, // The channel name
'new-tracking-record', // The event type
{latitude: 51, longitude: 3} // The coordinate data
);
For more detailed examples, Pusher have a tutorial on how to track our pizza in realtime with Pusher and Google Maps, and another tutorial on how to build a realtime map using Laravel.

Related

Google API is not returning the events created from UI

I am using googleapis in NodeJS to create & fetch the calendar events. I am using the following method to get the list of events.
const getEvents = async (dateTimeStart, dateTimeEnd,timeZone) => {
console.log("Date Start : " + dateTimeStart + " date end :" + dateTimeEnd + " time zone " + timeZone);
try {
let response = await calendar.events.list({
auth: auth,
calendarId: CALENDER_ID,
timeMin: (new Date(dateTimeStart)).toISOString(),
timeMax: (new Date(dateTimeEnd)).toISOString(),
timeZone: timeZone,
singleEvents: true,
maxResults: 9999,
orderBy: 'startTime
});
let items = response['data']['items'];
console.log(items);
return items;
} catch (error) {
console.log(`Error at getEvents --> ${error}`);
return 0;
}
};
The above method returns only events that are created programmatically via googleapis. If I create the events directly on the calendar from the browser this does not return those events.
Any idea how to fetch all events even if they are created from browser.
Based on what you were explaining about the behavior of the events being created by the service account instead of the actual users I think the problem is that the events created through API are being created under the Calendar ID of the service account, and the ones created by the users through API may have a different Calendar ID, therefore when you try to get the list of events, since you are probably using the Calendar ID from the service account you get only those events created using the API and not the ones created by the users through the web UI.
In this case it may be necessary to make sure that every event is being created under the exact same calendar ID through the web UI and the API so that all the events no matter if they were created through the API or web UI get listed as expected.
Let me know if this is useful, otherwise I can edit the response to add more clarification depending on your specific situation.

Using Places Library in App maker

Is there a way to call PlacesServices' getDetails function from App Maker?
I have the Place ID from the Geocoder but I'd like to be able to get details about the place.
At this time there is no built-in Places service in Apps Script and you'll need to through these steps to make it work:
Go to Google Cloud Console
Create a brand new project or use the project associated with your App Maker deployment:
Using left navigation menu go to APIs & Services -> Dashboard
Click + Enable APIs and Services button
Search for Google Places API Web Service and enable it
Go to APIs & Services -> Credentials and create new API key if you don't have one
Back in App Maker! =) Create a server script:
var API_KEY = 'PUT_YOUR_API_KEY_HERE';
var PLACES_URL = 'https://maps.googleapis.com/maps/api/place/details/json?placeid=';
function getPlaceDetails_(placeId) {
var URL = PLACES_URL + placeId + '&key=' + API_KEY;
var response = UrlFetchApp.fetch(URL);
var json = response.getContentText();
var placeDetails = JSON.parse(json);
return placeDetails;
}
This snippet is cornerstone for further scripting. You can use it with Calculated Model or just call it using google.script.run from client (note that for the second case you'll need to make this function public by removing underscore in the end of function name).

Eventbrite API Request Parameter

I want to get the list of popular events in San Francisco through
ajax request to Eventbrite API. Here's the code.
var city = 'San Francisco';
var query = "token=" + token + "&venue.city=" + city + "&popular=" + true + "&location.within=" + "10mi"
var $events = $("#events");
var settings = {
"async": true,
"crossDomain": true,
"url": "https://www.eventbriteapi.com/v3/events/?" + query,
"method": "GET",
"headers":{}
}
I'm getting results from other cities too. How can I set parameters to get results from San Francisco only? Also, I'm getting multiple copies of a single event. Is there any way to prevent this?
Your Query is Incorrect for API v3: When testing your query I received errors from the Eventbrite API. These errors are due to using the incorrect query parameters. For example 'popular' does not exist as a parameter. Make sure to test your queries via their playground https://www.eventbriteapi.com/v3/events/search?token='YOUR-OAUTH-TOKEN'.
SF Only Events: There is no way to set parameters in the Eventbrite query for events only in SF unless you include a small search radius around the latitude and longitude. That method could possibly exclude some popular SF events. The best way is to query all SF area events and then manipulate the data you get back by filtering out events whose Venue city is not San Francisco.
Popular Events: To truly get popular events you'd need to know how many tickets have been sold for each event (private data.) Instead, we need to use the sort_by parameter in our initial query to get the 'best' events. Unfortunately, 'best' is very vague in the API but all we have to work with.
Duplicate Events: Given the below query you will not get duplicate events.
Try the below jQuery AJAX method:
const sfSettings = {
url: 'https://www.eventbriteapi.com/v3/events/search/',
data: {token: 'YOUR-OAUTH-TOKEN', sort_by: 'best', 'location.latitude': 37.7749, 'location.longitude': -122.4194, expand: 'venue'},
crossDomain: true,
method: 'GET'
}
$.ajax(sfSettings).done(function(eventObject){
// All SF Area Events (Paginated by 50. Will only return first page.)
const events = eventObject.events;
// Create a new array of events whose venue is specifically in SF
const sfEvents = events.filter(function(event){
return event.venue.address.city === 'San Francisco';
});
});

Should I create a .factory in order to share a variable's value to two ajax requests?

Using angularjs I have made two ajax json requests, the first request is retrieving channel's online / offline status and the second ajax json request is for the channel's info (logo, name, status etc).
I assigned the variable signal to 'data.stream' which is the online / offline status for channels to share signal between json requests. In Google Developer console I am receiving a value of null. I did some research here http://www.ng-newsletter.com/posts/beginner2expert-services.html and found that using a service might be a solution. I followed the directions but I'm still unable to get the scope between json request to recognize signal.
I read that rootscope could be used but it's not recommend, not sure how true that is because a novice using angular but I want start my angular journey by applying best practices.
Recap: Using Angular Ajax to make a jsonp request to twitch api, I am make two requests one to retrieve the online / offline status of channels in my streamers array, and the other ajax json request is to retrieve the channel's info, and I need the scope of the variable signal which has been assigned the value data.stream to be seen between ajax jsonp requests. Please let me know if this is a logical approach or if I'm "going around the world again".
Here is a plunker: plnkr.co/edit/6sb39NktX7CwfnQFxNNX
// creating a service for signal ?
app.factory('signal', function() {
var signal = {};
return signal;
})
// declaring my TwitchController and dependencies
app.controller('TwitchController', ['$scope', '$http', 'signal', function($scope, $http, signal) {
// streamers array with array of channels
var streamers = ["freecodecamp", "storbeck", "terakilobyte", "habathcx", "RobotCaleb", "thomasballinger", "noobs2ninjas", "beohoff", "medrybw"];
$scope.imgs;
$scope.signal = signal;
var self = this;
//empty array
self.info = [];
for (var i = 0; i < streamers.length; i++) {
var url = "https://api.twitch.tv/kraken/channels/";
var streamUrl = "https://api.twitch.tv/kraken/streams/";
var callback = "/?callback=JSON_CALLBACK";
//json ajax request for channels online and offline status
$http.jsonp(streamUrl + streamers[i] + callback).success(function(data) {
//provides status of shows online and offline
signal = data.stream;
console.log(signal)
});
// json ajax request for channels and channel's info
$http.jsonp(url + streamers[i] + callback).success(function(data) {
// if channel does not have a logo image, this jpg will be the placeholder
// if statement test channel status (online or offline)
if (!signal) {
signal = "offline";
} else if (signal) {
signal = 'online';
}
// pushing retreive data from twitch.tv into array self.info
self.info.push(data);
});
Your issue here is async call to $http. You need to use $http.then and chain the promises. You do not need a factory for this instance but it is best practice to have one that just returns your info object. I didn't know exactly the format you wanted so I created one. Here is the plunker: http://plnkr.co/edit/ecwk0vGMJCvkqCbZa7Cw?p=preview
var app = angular.module('Twitch', []);
// declaring my TwitchController and dependencies
app.controller('TwitchController', ['$scope', '$http', function($scope, $http) {
// streamers array with array of channels
var streamers = ['freecodecamp', 'storbeck','terakilobyte', 'habathcx', 'RobotCaleb', 'thomasballinger', 'noobs2ninjas', 'beohoff', 'medrybw' ];
//empty array
$scope.info = [];
var url = 'https://api.twitch.tv/kraken/channels/';
var streamUrl = 'https://api.twitch.tv/kraken/streams/';
var callback = '/?callback=JSON_CALLBACK';
angular.forEach(streamers, function(stream) {
//json ajax request for channels online and offline status
$http.jsonp(streamUrl + stream + callback).then(function (data) {
//provides status of shows online and offline
// json ajax request for channels and channel's info
$http.jsonp(url + stream + callback).then(function (channelData) {
// pushing retrieve data from twitch.tv into array self.info
$scope.info.push(
{
url: url + stream,
stream: stream,
status: !data.stream ? 'offline' : 'online', // ternary statement test channel status (online or offline)
logo: channelData.data.logo ? channelData.data.logo : 'placeholderlogo.jpg' // if channel does not have a logo image, this jpg will be the placeholder
}
);
});
});
});
}]);

How to export/link user e-mails?

So we're using Parse.com's signup, and e-mails of user signups go into the User Class. We're also using MailChimp at the moment for our campaign software. How can we export or link the two so that any e-mails from signups go to our MailChimp lists?
I know that Parse has some Cloud Module integrations with Mandrill and SendGrid, but nothing with MailChimp directly.
Maybe these articles can help you:
https://www.parse.com/questions/mailchimp
Github project: Mailchimp API + Mandrill API optimized for Parse.com Cloud Code
https://github.com/icangowithout/parse-mailchimp/commit/0d75b8be9775347efd939c8715d5d2b13076353c
var api_key = "YOUR_MAILCHIMP_API_KEY";
// use https and last verison
var options = {secure: true, version: "1.3"};
// Set the path to the mailchimp module
// If you cloned the mailchimp lib somewhere else, it's time to set this
// value properly
var module_path = "cloud/libs/mailchimp/";
var MailChimpAPI = require(module_path+"MailChimpAPI.js");
var myChimp = new MailChimpAPI(api_key, options, module_path);
myChimp.ping({}, function(error, data){
// data is a string or JSON parsed object
if(error){
// Oops… there was a problem...
}else{
// Do something with the data
}
// Handle what to do with the ping
});
//or
// Parse callback style
myChimp.ping({}, {
success: function(data){
// data is a string or JSON parsed object
// Howdy! The ping worked!
},
error: function(error){
// Something went wrong...
}
});

Resources