Meteor geo location from browser package - meteor

I've tried searching atmosphere and the web for any package to get users Geo location (latitude, longitude) while accessing the app using their desktop browsers but couldn't find any. Existing applications serve mobile only ex. MDG Geo Location Can someone please tell me how to get the user geo location (latitude, longitude) from desktop through Meteor? Thanks

I know this is an old post, however, thought of putting this through.
You can try using the gunjansoni:html5-api package. It has geo location and lot of other HTML5 Apis to play with.
After you install the package on you client
var html5api = new Html5Api();
and then request for geo location permissions:
var geoLocation = html5api.geoLocation();
Once you have the permissions, get the location.
if (geoLocation) {
geoLocation.getLocation(function(err, res){
if (err) console.log(err);
else console.log(res);
});
}
The result will be something like this:
{
accuracy: 30 // in meters
altitude: null
altitudeAccuracy: null
heading: null
latitude: <latitude>
longitude: <longitude>
speed: null
timestamp: 1457901207220
}
Or you can watch a user's location
if (geoLocation) {
geoLocation.watch(function (err, res) {
if (err) console.log(err);
else {
// the result will be in res.result
console.log(res.result);
Meteor.setInterval(function () {
// to stop watching a location, you need a watchId which is available in res.watchId when the watch started
geoLocation.stopWatching(res.watchId);
}, 30 * 1000);
}
});
}

Related

Cloud vision api face detection no image present error

We are getting No image present. error while attempting face detection with the cloud vision api.
We are using code from the official documentation.
Please see the code below.
const request1={
"requests":[
{
"image":{
"content": imgdatauri //It contains image data uri
},
"features": [
{
"type":"FACE_DETECTION",
"maxResults":1
}
]
}
]
};
client
.annotateImage(request1)
.then(response => {
console.log(response);
response.send(response);
})
.catch(err => {
console.error(err);
response.send(err);
});
Here is the error message.
Error: No image present.
at _coerceRequest (/rbd/pnpm-volume/e40024d2-3d05-4f3d-a435-6d4e6ca96fb0/node_modules/.registry.npmjs.org/#google-cloud/vision/1.1.3/node_modules/#google-cloud/vision/src/helpers.js:69:21)
at ImageAnnotatorClient.<anonymous> (/rbd/pnpm-volume/e40024d2-3d05-4f3d-a435-6d4e6ca96fb0/node_modules/.registry.npmjs.org/#google-cloud/vision/1.1.3/node_modules/#google-cloud/vision/src/helpers.js:224:12)
at PromiseCtor (/rbd/pnpm-volume/e40024d2-3d05-4f3d-a435-6d4e6ca96fb0/node_modules/.registry.npmjs.org/#google-cloud/promisify/1.0.2/node_modules/#google-cloud/promisify/build/src/index.js:71:28)
at new Promise (<anonymous>)
at ImageAnnotatorClient.wrapper [as annotateImage] (/rbd/pnpm-volume/e40024d2-3d05-4f3d-a435-6d4e6ca96fb0/node_modules/.registry.npmjs.org/#google-cloud/promisify/1.0.2/node_modules/#google-cloud/promisify/build/src/index.js:56:16)
We would like to know what we need to do to resolve the issue.
Method 1:
In case of vision API, if image is stored locally you must convert that image to base64 string. Now this converted string is passed as value to content.
Make sure that you are converting image to base64 string and then passing to the content value.
There are some services available online to convert image to base64 string. You can also convert image to base64 by writing a piece of code. You can find services online and select anyone them. I am providing link to one service.
https://www.browserling.com/tools/image-to-base64
Method 2:
You can provide public url of image to vision API.
{
"requests":[
{
"image":{
"source":{
"imageUri": PUBLIC_URL
}
},
"features":[
{
"type":TYPE_OF_DETECTION,
"maxResults":MAX_NUMBER_OF_RESULTS
}
]
}
]
}
Method 3:
You can create bucket and put image there.
Now you can provide this image object URL or path.
I think this will help you.
Thank you.
I have created a Cloud Function with Cloud Storage Trigger, my function gets triggered ( with event ) when I upload an image file I can see there is event.mediaLink event.selfLink, I tried using both to load image, but it keeps complaining about No Image being present
here is the code
exports.analyzeImage = function(event) {
const vision = require('#google-cloud/vision');
const client = new vision.ImageAnnotatorClient();
console.log('Event', event.mediaLink)
let image = {
source: {imageUri: event.mediaLink}
};
return client.labelDetection(image).then(resp => {
let labels = resp[0].labelAnnotations.map( l => {
return {
description: l.description,
score: l.score
};
});
return labels;
// const dataset = bigquery.dataset('dataset')
// return dataset.table
}).catch(err => {
console.error(err)
})
}

How to get Exact User location by Using maps API?

May be similar question asked before. But I am in the middle of finding the location. When I try the following code it shows my internet providers location. and which doesnot show my current location.
function ipLookUp () {
$.ajax('http://ip-api.com/json')
.then(
function success(response) {
console.log('User\'s Location Data is ', response);
console.log('User\'s Country', response.country);
getAdress(response.lat, response.lon)
},
function fail(data, status) {
console.log('Request failed. Returned status of',
status);
}
);
}
function getAddress (latitude, longitude) {
$.ajax('https://maps.googleapis.com/maps/api/geocode/json?latlng=' + latitude + ',' + longitude + '&key=***************************************')
.then(
function success (response) {
console.log('User\'s Address Data is ', response)
},
function fail (status) {
console.log('Request failed. Returned status of',
status)
}
)
}
if ("geolocation" in navigator) {
// check if geolocation is supported/enabled on current browser
navigator.geolocation.getCurrentPosition(
function success(position) { // for when getting location is a success
console.log('latitude', position.coords.latitude, 'longitude', position.coords.longitude);
getAddress(position.coords.latitude, position.coords.longitude);
},
function error(error_message) { // for when getting location results in an error
console.error('An error has occured while retrieving location', error_message);
ipLookUp();
}
);
} else {
// geolocation is not supported
// get your location some other way
console.log('geolocation is not enabled on this browser')
ipLookUp()
}
It shows my ISP city name. But I want my current location name like this sample image.
This is sample image. and it shows my current city and street name in google search results page. But when I use the above code.it shows like this.
AS55836 Reliance Jio Infocomm Limited"
city: "Coimbatore"
country: "India"
isp: "RJIL Tamilnadu LTE SUBSCRIBER PUBLIC"
org: "Reliance Jio infocomm ltd"
Looking some experts advice to trace the location exactly.

Can't upload image to EC2 Instance with CollectionFS/GridFS ERR_CONNECTION_REFUSED

I'm working on a simple Meteor app which manages profile pictures, while working in local my project is working fine.
But after deploying it on an AWS EC2 instance (With Meteor-Up), every works fine, except the image upload.
I'm using CollectionFS (cfs:standard-packages, cfs:gridfs).
Here's the code :
// Collection definition
Images = new FS.Collection("images", {
stores: [new FS.Store.GridFS("original")]
});
Images.allow({
'insert': function () {
return true;
},
'update': function () {
return true;
},
'download':function(){
return true;
}
});
// Event to upload the image
"click .js-validate"(event, instance){
Images.insert(instance.file.get(), function (err, fileObj) {
if(err){
console.log("Error");
console.log(err);
}else{
console.log("No error");
console.log(err);
Meteor.call('updatePP', fileObj._id, function(){
Modal.hide("Modal_update_pp");
});
}
});
}
The security rules for my EC2 instance :
And here's the error showing when i execute the event which execute the Images.insert function.
The error ERR_CONNECTION_REFUSED is showing.
I'm able to get the image id, but the image isUploaded function return false :
Why am i having this error and how can i solve this problem ?
Is it due to my EC2 configuration or the code inside my Meteor Project ? Thanks !
I’d suggest to switch to ostrio:files which is fully documented and up to date. GridFS is really old and buggy. You can then save your files securely to a S3 instance and keep your MongoDB size low.

Meteor reading data from a file stored on server

I want to show some data points on the client side, and I want to get the latitude, longitude and summary from a file stored on the server.
I have read a lot of posts saying to use papaParse using Meteor methods but I am not able to make it work.
Can you guys point me to right direction, my questions are:
In which folder to should I store a .txt, .csv or .json file in Meteor?
How to access it from the client and return the read data to client for display.
You can put your static files into private folder on the server and get them through Assets.
For exmaple, you have a data.json file in your private folder.
Method to get this data:
Meteor.methods({
getData() {
return JSON.parse(Assets.getText('data.json'));
}
});
You can now call this method on the client:
Meteor.call('getData', function(err, res) {
console.log(res);
});
UPD
Ok, how to display it.
Meteor.call runs async, so we will use reactivity to update our view on result.
Here is how we can display data on ourData template.
<template name="ourData">
<!-- Here you may want to use #each or whatever -->
<p>{{ourData}}</p>
</template>
Template.ourData.onCreated(function() {
this.ourData = new ReactiveVar();
Meteor.call('getData', (err, res) => {
if (err) {
console.error(err);
} else {
// Putting data in reactive var
this.ourData.set(res);
}
});
});
Template.ourData.helpers({
ourData: function() {
// Helper will automatically rerun on method res
return Template.instance().ourData.get();
}
});
reactive-var package required or you can also use Session.

Halt insert till function returns result

In my visits collection I have a geocodeVisit function which uses the Google geocoding service to gecode an address. The problem is that the meteor script is typically run before the google maps API is loaded, resulting in an Exception while invoking method 'visitInsert' ReferenceError: google is not defined error. So I need to wait with the inser till the geocoding has finished. How can I do this? This is the visits collection:
Meteor.methods({
visitInsert: function(visitAttributes) {
check(Meteor.userId(), String);
check(visitAttributes, {
nr: String,
visit_date: String
});
var properties = {
userId: Meteor.userId(),
position: geocodeVisit(visitAttributes.address)
};
var visit = _.extend(visitAttributes, properties);
var visitId = Visits.insert(visit);
return {
_id: visitId
};
}
});
geocodeVisit = function (address) {
this.unblock;
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
return results[0].geometry.location;
}
});
}
Instead of including the maps api using a script tag in the HTML code, you should download the file to your "/lib" directory. Everything in that directory is loaded before any Meteor code is run.
Also, you are going to run into an async problem with you code. You are trying to return the value from the success callback in the geocodeVisit function. The two approaches that I can see working are:
Figure out how to make synchronous requests using the maps api. Maybe this: Synchronous request in Node.js
Go ahead and insert the visit without the location info. Then make the geocode request to the maps api and update the entry once the response comes back. Personally, this is the approach I would take.

Resources