Do you know any way to find correct location (lon,lat) using python or js
I am trying the following python code but it doesnt give me my correct current location
import json
from urllib.request import urlopen
from requests import get
import geocoder
url = 'http://ipinfo.io/json'
response = urlopen(url)
data = json.load(response)
g = geocoder.ip('me')
print(g.latlng)
"""loc = get('https://ipapi.co/{}/json/'.format(data['ip']))
print(loc.json())"""
send_url = 'http://freegeoip.net/json'
r = get(send_url)
j = json.loads(r.text)
lat = j['latitude']
lon = j['longitude']
print("lat {} lon {}".format(lat, lon))
Your IP Address doesn't/can never give you the correct location of where you are it. The location can from the internet can only be used to get the country and MAYBE the state of the user.
The location given is usually where the Sub-Station of your ISP is located.
In javascript you can do this
let position;
navigator.geolocation.getCurrentPosition((pos) => position = pos.coords &&
console.log(position));
after that you can just do:
-position.latitude
-position.longitude
It's not the most accurate precision, but in chase you want something more precise, you can look for watchPosition() of Geolocation in MDN documentation.
Related
I have used the http link to import the package:
var d3Url = "https://gmousse.github.io/dataframe-js/dist/dataframe.js";
eval(UrlFetchApp.fetch(d3Url).getContentText());
But when I do const df = new DataFrame(company_df[1], company_df[0]), it gives a Reference Error: DataFrame is not defined.
I have also tried to put var DataFrame = dfjs.DataFrame; at the top. But, no luck.
How can I correctly import the package?
Try to put
var Url = "https://gmousse.github.io/dataframe-js/dist/dataframe.min.js";
eval(UrlFetchApp.fetch(Url).getContentText());
in the same file of var DataFrame = dfjs.DataFrame;
It works although I don't know the reasons.
I am Trying to call External URL From Suitelet its throwing 406 Error.
var user_name = ‘username’;
var password = ‘password’;
var url=”Url”;
var auth = nlapiEncrypt(user_name+’:’+password,’base64′);
var headers = new Array();
headers[“Content-Type”] = “application/json”;
headers[“Authorization”] = ‘Basic ‘+auth+”;
headers[“Token”] = ‘abcdddd-djfjjff-djd/dkdkd’;
var token_res=nlapiRequestURL(url, null,headers);
var token_response_XML = token_res.getBody();
nlapiLogExecution(‘DEBUG’, ‘token_response_XML’, token_response_XML);
Anyone Suggest Please?
Thanks in Advance
Based on a quick Google search (it's been a LONG time since I've seen that error code), it looks like your other system is not returning the data in the manner that is expected. I would suggest testing with something like the chrome ARC (Advanced REST Client) extension so that you can see the entire process and get it all perfected. Here is the page I read up on 406 errors to refresh my memory.
406 Not Acceptable
I've been searching for ways to restrict access to an API made for using a AWS Lambda function written on javascript.
I've found documentation on how to use AWS Signature S4, but I still do not understand it.
According to creating a signature, after applying the pseudocode I should get the signature to be placed on the header.
I've found the following code that addresses this point:
// Example of signature generator
var crypto = require("crypto-js");
function getSignatureKey(Crypto, key, dateStamp, regionName, serviceName) {
var kDate = Crypto.HmacSHA256(dateStamp, "AWS4" + key);
var kRegion = Crypto.HmacSHA256(regionName, kDate);
var kService = Crypto.HmacSHA256(serviceName, kRegion);
var kSigning = Crypto.HmacSHA256("aws4_request", kService);
return kSigning;
}
console.log(getSignatureKey(crypto,'secretkey','date','us-east-2','iam'));
Here comes my first question, I do not know what should be the output of getSignatureKey()? This is because on the documentation it is a very long string, while the output I got was {words:[x,x,x,x,x,x,x,x],sigBytes: 32},where the x are random numbers.
Moreover, after getting the signature and filling the header for the request with the "authorization" field and others, how do I filter unproper requests? Do I have to create a policy for the AWS API so it only allows signed requests? Here I guess I should follow Signing Requests.
Thanks!
Here is the simple implementation of Signed URL's. aws-cloudfront-sign package offers simpler implementation.
var cfsign = require('aws-cloudfront-sign');
var signingParams = {
keypairId: process.env.PUBLIC_KEY,
privateKeyString: process.env.PRIVATE_KEY,
// Optional - this can be used as an alternative to privateKeyString
privateKeyPath: '/path/to/private/key',
expireTime: 1426625464599
}
// Generating a signed URL
var signedUrl = cfsign.getSignedUrl(
'http://example.cloudfront.net/path/to/s3/object',
signingParams
);
https://aws.amazon.com/blogs/developer/creating-amazon-cloudfront-signed-urls-in-node-js/
Purpose of SignedURL is to serve Private Contents.
More details at,
http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/PrivateContent.html
Hope it helps.
Hi I am buliding my first web app using javascript and fetching data using API from www.openweathermap.org/
I have used the API key as mentioned in the documentation still it is giving an error of unauthorization. Can there be any other reason for this error while calling a function or so . Thank you in advance.
var APPID = "my_secret_key";
var temp;
var loc;
var icon;
var wind;
var humidity;
var direction;
function updateByZip(zip){
var url = "http://api.openweathermap.org/data/2.5/weather?" +
"zip = " + zip +
"&APPID =" + APPID ;
sendRequest(url);
}
function sendRequest(url){
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
var data = JSON.parse(xmlhttp.responseText) ;
var weather = {};
weather.wind = data.wind.speed;
weather.direction = data.wind.deg;
weather.loc = data.name;
weather.temp = data.main.temp;
weather.icon = data.weather[0].id;
weather.humidity=data.main.humidity;
update(weather);
}
};
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
It's the spaces near the equal signs in your URL. It's likely urlencoding the space and sending your parameter as APPID%20 which is not being recognized as valid.
var url = "http://api.openweathermap.org/data/2.5/weather?" +
"zip=" + zip +
"&APPID=" + APPID;
for future users, as i was having 401 error but solved it differently.
Error:
Invalid API key. Please see http://openweathermap.org/faq#error401 for more info
API calls responds with 401 error:
You can get the error 401 in the following cases:
You did not specify your API key in API request.
Your API key is not activated yet. Within the next couple of hours, it will be activated and ready to use.
You are using wrong API key in API request. Please, check your right API key in personal account.
You have free subscription and try to get access to our paid services (for example, 16 days/daily forecast API, any historical weather data, Weather maps 2.0, etc). Please, check your tariff in your [personal account]([price and condition]).
here are some steps to find problem.
1) Check if API key is activated
some API services provide key information in dashboard whether its activated, expired etc. openWeatherMap don't.
to verify whether your key is working 'MAKE API CALL FROM BROWSER'
api.openweathermap.org/data/2.5/weather?q=peshawar&appid=API_key
replace API_key with your own key, if you get data successfully then your key is activated otherwise wait for few hours to get key activated.
2) Check .env for typos & syntax
.env is file which is used to hide credentials such as API_KEY in server side code.
make sure your .env file variables are using correct syntax which is
NAME=VALUE
API_KEY=djgkv43439d90bkckcs
no semicolon, quotes etc
3) Check request URL
check request url where API call will be made , make sure
It doesn't have spaces, braces etc
correct according to URL encoding
correct according to API documentation
4) Debug using dotenv:
to know if you dotenv package is parsing API key correctly use the following code
const result = dotenv.config()
if (result.error) {
throw result.error
}
console.log(result.parsed)
this code checks if .env file variables are being parsed, it will print API_KEY value if its been parsed otherwise will print error which occur while parsing.
Hopefully it helps :)
Others suggestion
5) Check location of .env file
look for location of .env file in your directory, moving it to root directory might help (suggested in comments)
For those who followed the previous answers and are still facing the 401 issue: it seems it is now required to access the the API via HTTPS --- at least that's the case for me. Some older guides and tutorials might continue to use http:// in their code, so you'll have to change it to https://.
As far as I know, there is no mention of this in OpenWeather's official docs, and they don't include the protocol in their examples too.
I was using the following code to obtain the lat and lng values from user input. It seemed to be working fine, until just recently.
if (status == google.maps.GeocoderStatus.OK) {
var lat = parseFloat(results[0].geometry.location.wa).toFixed(3);
var lng = parseFloat(results[0].geometry.location.xa).toFixed(3);
....
Now if I console.log results[0].geometry.location I get (51.4793388, -2.5933342) { va=51.4793388, wa=-2.5933342}.
It appears as if xa has changed to va. What is the correct way to reference these values?
I recently ran into the same issue on my Google Map API 3.0 application. Basically, the wa and xa variables if i remember correctly are just LatLng() variables. So you can call them this way:
results[0].geometry.location.lat().toFixed(3);
results[0].geometry.location.lng().toFixed(3);
where va = lat and wa = lng