nchaulet / node-geocoder

nodejs geocoding library
http://nchaulet.github.io/node-geocoder/
MIT License
928 stars 214 forks source link

Unhandled Rejection (TypeError): net.isIPv4 is not a function #306

Closed zhg-kj closed 4 years ago

zhg-kj commented 4 years ago

Hello, I am trying to use your geocoder in a for loop to loop over an array of markers in order to covert addresses to latitudes and longitudes on React. When I try to do this however, I receive the title error and the react app points towards this:

    const temp = await geocoder.geocode(markers[i].address)

I am not completely sure what that means, to me it seems like it does not recognize geocode as a function?

Here is the rest of the related code:

const NodeGeocoder = require('node-geocoder');
const options = {
    provider: 'google',
    apiKey: key
};
const geocoder = NodeGeocoder(options);
//unrelated code inbetween
let markers = [
    {
      name: "Costco Wholesale",
      address: "9151 Bridgeport Rd, Richmond, BC V6X 3L9",
      position: { lat: 49.166590, lng: -123.133569 },
      placeID: 'ChIJWc2NzuF0hlQRDu0NNhdQCjM'
    }
  ];
//Unrelated code inbetween
async findLatLong(){
    for(let i = 0; i < markers.length; i++){
        const temp = await geocoder.geocode(markers[i].address)
        markers[i].position.lat = temp.latitude;
        markers[i].position.lng = temp.longitude;
    }
  }

I apologize if it is a stupid mistake, I am still a JS noob, but I have definitely given it my best shot before posting here :/

TIA!

zhg-kj commented 4 years ago

Changed it so that I am using the geocoder in my backend. Works like a charm.