Google Map not displaying in Chrome / Firefox browser - browser

I am trying to test Geolocation in HTML 5 in my browser. But for some reason, it is not displaying the lat and long for my place. Nor even the error message
Why is the lat and long not displaying. please assist. I tried on Chrome and FF. same result. Does it not display result all time or takes time
window.onload = checkLocation;
function checkLocation() {
//we put the if condition that will check if the browser supports geplocationn feature or not
if(navigator.geolocation) {
//if yes, then call the getCurremtPosition method and pass in a handler function ()
navigator.geolocation.getCurrentPosition(showLocation, showError);
// And we’re calling the geolocation object’s getCurrentPosition method with one argument, the success callback.
}else {
alert(' Hey No locator for your browser');
}
}
function showLocation(position) {
//position parameter is passed so as to get getCurrentPosition’s handler is passed a position, which contains the latitude and longitude of your location
// get the lat and lon of location from the cords object
var lat = position.coords.lat;
var lon = position.coords.lon;
var content = document.getElementById('myLocation');
content.innerHTML = ' Your latitude position is: ' + lat + ' and your Longtitude position is: ' + lon + '</br>';
}
function showError(error) {
var errorList = {
//We create an object with three properties named zero to three.
//These properties are strings with an error message we want to associate with each code
0: 'Unknown error',
1: 'Permission denied by user',
2: 'Position not available',
3: 'Request timed out'
};
var errorMsg = errorList[error.code];// use error code property to access the error list []
if(error.code == 0 || error.code == 2) {
errorMsg = errorMsg + " " + error.message; // use erroo message property ro access the value in error list
}
var content = document.getElementById('myLocation');
content.innerHTML = erroMsg;
}

BTW i have found the issue. While calling the map api script, make sure the url starts with // and not http. Let google decide how it wants to serve the api file.

Related

Is there any way with suitescript 1.0 to run a server side function on a client script (like getFieldText)?

I was writing a client script for work and part of it involved getting getting the value of the cost category's text to display to the user. Unfortunately, that seems to only be a server side function. I've seen some posts about how to accomplish this in Suitescript 2.0, but for whatever reason, I can't seem to get Suitescript 2.0 scripts to work on Netsuite. Is there any way to run the getFieldText function from the client side script in 1.0?
I was able to use a separate Suitelet script to get the job done.
Code from the suitelet:
function getFTxt(request, response){
try{
var recordid = request.getParameter('rid');
var recordtype = request.getParameter('rt');
record = nlapiLoadRecord(recordtype, recordid);
var fieldName = request.getParameter('fn');
fieldText = record.getFieldText(fieldName);
response.write(fieldText);
}
catch(e){
var err = '';
if ( e instanceof nlobjError ){
err = 'System error: ' + e.getCode() + '\n' + e.getDetails();
}
else{
err = 'Unexpected error: ' + e.toString();
}
var errmsg = 'Error: ';
errmsg+= '\n' + err;
nlapiLogExecution( 'ERROR', 'Error is: ', errmsg);
response.write("");
}
}
Code from my original script:
function getFieldText(field,item){
var url = nlapiResolveURL('SUITELET', 'customscriptScriptIdGoesHere', 'customdeployDeployIdGoesHere') + '&rid=' + item.getId() + '&rt=' + item.getRecordType() + '&fn=' + field;
var response = nlapiRequestURL(url);
return response.getBody();
}
Then, whenever I wanted to get the field text for an item, I'd call that function from within the script.
be sure to replace the script and deployment id to that of the suitelet.

List element of a dataLayer with puppeteer

i'm doing a web scraping bot thanks to puppeteer, and i want to verify a field of a dataLayer on some url thanks to cloud functions on Google Cloud Plateform.
right now i'm using the await page.$('dataLayer') and it return a "true", so it find the dataLayer.
there is the dataLayer on my browser (not puppeteer)
my code:
exports.datalayer = async(page) => {
//verfify if there is a dataLayer
let dl = await page.$('dataLayer')
if(dl =! null){
console.log('DataLayer found')
//want to do something like that
for(let key in dl){
let value = dl[key]
console.log('key: ' + key + ' value: ' + value)
}
//or like that
dl.forEach(element => {
console.log(element)
});
}else{
console.log('error with the dataLayer')
}
}
In order to catch the OnetrustActiveGroups data.
when i do the forEach method i get this error:
and for the for method i get this error:
better use the page.evaluate('dataLayer')
then stringify it or use it as you want :)
and with the evaluate the for(let item in dl) works fine !

nodejs dynamically increment JSON object property without getting undefined on the first try

I need to dynamically create and increment a property in a JSON object. My code needs to check for undefined on the first try, else it will error out if I try to simply increment a non-existing property.
The code works, but I'm itching for a way to simplify the code below?
let errorcount = {}
let code = "404" // eg. 404 response code - this is dynamic, so it can be any response code returned by API
// increment operation, to be called after getting response code from API
// can this be made simpler??
if (errorCount[`response ${code}`] === undefined) {
errorCount[`response ${code}`] = 1
} else {
errorCount[`response ${code}`]++
}
console.log(JSON.stringify(errorCount))
// errorcount = {"response 404" : 800 } // eg. result for 404 errors aggregated
You could do that it is slightly shorter.
const errorcount = {}
const code = "404" // eg. 404 response code - this is dynamic, so it can be any response code returned by API
// increment operation, to be called after getting response code from API
// can this be made simpler??
const responseString = `response ${code}`
errorCount[responseString ] = errorCount[responseString] ? errorCount[responseString]+1 : 1 ;
console.log(JSON.stringify(errorCount))
// errorcount = {"response 404" : 800 } // eg. result for 404 errors aggregated
You could also prepopulate the codes in a file.js. I would probably do it myself that way.
And then the end result would be:
const errorCount = { 400:0, 401:0, 402:0,... }
errorCount[code] +=1;
console.log(JSON.stringify(errorCount))
Writing this as an answer as the OP requested.
You can do it like this to make it shorter, but the logic is basically the same.
errorCount[`response ${code}`] = (errorCount[`response ${code}`] || 0) + 1;
The final code snippet looks like:
let errorcount = {}
let code = "404" // eg. 404 response code - this is dynamic, so it can be any response code returned by API
// increment operation, to be called after getting response code from API
// can this be made simpler??
errorCount[`response ${code}`] = (errorCount[`response ${code}`] || 0) + 1;
console.log(JSON.stringify(errorCount))
// errorcount = {"response 404" : 800 } // eg. result for 404 errors aggregated

if object is invalid json format - forward contents forward contents anyway - NODEJS

I am currently forwarding cloudwatch alarms to slack using a nodejs lambda function I found on github, however, when it receives a custom alert from one of our customers datacenters, the string is not in a JSON format, so it will not print the alert.
I am looking at rewriting the handleCatchAll() function to handle the string and just forward it to slack in its current format, but am having issues identifying the object.
Below is the code i am trying to edit, I need to write an if statement that will identify the object, say "if JSON.stringify fails, then render the message without JSON.stringify and input its value into 'description'"
var description = ""
if ()
{
else if ()
{
for(key in message) {
var renderedMessage = typeof message[key] === 'object'
? JSON.stringify(message[key])
: message[key]
description = description + "\n" + key + ": " + renderedMessage
}
}
}
You can use this script to convert text input into json if the text is a valid JSON object, or else keep the original text.
const isJSON = str => {
try {
return (JSON.parse(str) && !!str);
} catch (e) {
return false;
}
}
const regulizeRequestBody = body => isJSON(body) ? JSON.parse(body) : body;

Error after using request parameters in function

I’m getting an error when trying to fetch data with the instagram-node package while using request parameters.
Making the call without parameters but hard coded values works without any errors and gives me the right result.
When I use the parameters, as shown below, I get the following error:
{ [Error: Wrong params "lat" & "lng"] retry: [Function] }
This is my code:
//http://localhost:8080/photos/2000/52.3677985/4.8852246
app.get('/photos/:dist/:longitude/:latitude', function(req,res) {
var dist = req.params.dist;
var longitude = req.params.longitude;
var latitude = req.params.latitude;
console.log(dist + " " + longitude + " " + latitude);
ig.media_search(longitude, latitude, {distance: dist},
function (err, medias, remaining, limit) {
if (err) {
console.log(err);
} else {
res.render('pages/index', {grams: medias});
}
});
Logging the parameters gives me the required values, but they don’t seem to be defined when making the ig.media_search() call.
Am I missing something here?
The first thing that I'm seeing is that you're sending in latitude and longitude in backwards. The signature is:
media_search = function(lat, lng, options, cb) {}
Secondly, this is the line that is throwing your error from instagram-node:
if(typeof lat !== 'number' || typeof lng !== 'number') {
return handle_error(new Error('Wrong params "lat" & "lng"'), cb, retry);
}
I'm going to guess that you're sending in string values that have the numbers you want as they were parsed out of the url string. If you try calling it like this, you might see better results:
//http://localhost:8080/photos/2000/52.3677985/4.8852246
app.get('/photos/:dist/:longitude/:latitude', function(req,res) {
// Cast as numbers to send into instagram.
var dist = Number(req.params.dist);
var longitude = Number(req.params.longitude);
var latitude = Number(req.params.latitude);
console.log(dist + " " + longitude + " " + latitude);
ig.media_search(latitude, longitude, {distance: dist},
function (err, medias, remaining, limit) {
if (err) {
console.log(err);
} else {
res.render('pages/index', {grams: medias});
}
});
By the way, I've never used this package before. If you go from the npm page for this package you can find a link to the github repo for it. If you look at their package.json you can find a main value that will lead you to the entry point for the package. In that file (lib/instagram.js) you can Ctrl+F for media_search and find the function in you're calling. Just thought you might want to know how to go through and debug something like this. :)

Resources