1

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);
});
});
amelvin
  • 8,919
  • 4
  • 38
  • 59
MatejMecka
  • 1,448
  • 2
  • 24
  • 37

1 Answers1

1

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.

Community
  • 1
  • 1
Alexander Graebe
  • 797
  • 5
  • 10
  • I entered some US addresses, France , From Kuala Lumpur city's that Uber was available(Checked Uber's site) – MatejMecka May 22 '16 at 09:52
  • As of version 0.9.4, there is no lon & lat check in this method anymore. It's up to the Uber API to decide if the values should be taken. Please create an issue on GitHub in case you're still facing some issue. Thanks! – Alexander Graebe May 22 '16 at 10:41