Reputation: 1486
I'm trying to make a script in Node.JS when entering the address and it tells you the products in the place you are. But I get [Error: Invalid latitude & longitude]
I do that with geocoding but every time I run the app with the same or different address I get that. Here is the code
var Uber = require('node-uber');
var geocoderProvider = 'google';
var uber = new Uber({
client_id: 'KEY',
client_secret: ' key',
server_token: 'key',
redirect_uri: 'uri',
name: 'Uber product list'
});
var httpAdapter = 'http';
var geocoder = require('node-geocoder')(geocoderProvider, httpAdapter);
geocoder.geocode('Address', function(err, res) {
console.log(res);
var latitude = res[0]["latitude"]
var longitude = res[0]["longitude"]
console.log(latitude);
console.log(longitude);
uber.products.getAllForLocation(latitude, longitude, function (err, res) {
if (err) console.error(err);
else console.log(res);
});
});
Upvotes: 1
Views: 377
Reputation: 797
UPDATE: As of May 17th, the method
getAllForLocation
does not check for lat & lon validity anymore. It's up to the Uber API endpoint to decide if the values should be taken.
I contributed to the node-uber project. The method getAllForLocation
uses a RegEx to identify if the lat & lon values fall into the correct range. It creates a "[lat], [long]" string and tries to match this RegEx (taken from Iain Fraser):
^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),\s*[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$
Do you mind checking if your specific values are matched here: https://regex101.com/r/wQ8bX9/1 ?
I just checked some sample addresses with google as geocode-provider, but I can't reproduce the error.
Upvotes: 1