<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Zach Porteous on Medium]]></title>
        <description><![CDATA[Stories by Zach Porteous on Medium]]></description>
        <link>https://medium.com/@zachporteous?source=rss-67e7bca4e1c6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*W3fPg7YSIaskufOQ</url>
            <title>Stories by Zach Porteous on Medium</title>
            <link>https://medium.com/@zachporteous?source=rss-67e7bca4e1c6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 13:27:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@zachporteous/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Geocode multiple addresses with Google API and Node.js using promises]]></title>
            <link>https://medium.com/@zachporteous/geocode-multiple-addresses-with-google-api-and-node-js-using-promises-aaf97e79613e?source=rss-67e7bca4e1c6------2</link>
            <guid isPermaLink="false">https://medium.com/p/aaf97e79613e</guid>
            <category><![CDATA[geospatial]]></category>
            <category><![CDATA[promises]]></category>
            <category><![CDATA[geocoding]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[google-api]]></category>
            <dc:creator><![CDATA[Zach Porteous]]></dc:creator>
            <pubDate>Sat, 01 Jan 2022 21:36:53 GMT</pubDate>
            <atom:updated>2022-01-01T21:36:53.539Z</atom:updated>
            <content:encoded><![CDATA[<p>Working as GIS analyst, I have constant exposure to Python and automation on a day to day basis. Recently I came up on a limitation in the <a href="https://googlemaps.github.io/google-maps-services-python/docs/index.html">python client</a> library for the <a href="https://developers.google.com/maps/documentation/geocoding/overview">Google’s API geocoding service</a>: it does not support asynchronous requests. This is a problem because I’ve found that google has the most accurate return results so I wanted to continue to use it, but I often would have hundreds (or thousands) of addresses to geocode in my script. Sending synchronous requests can be very time consuming.</p><p>On a different web application project I had a similar task but this time, I had node.js as my backend and could use Promises. the user uploads a file, and then my backend reads it, and attempts to geocode the columns.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/80611ad0b13eeb2fc31e8b61ca552fca/href">https://medium.com/media/80611ad0b13eeb2fc31e8b61ca552fca/href</a></iframe><ol><li>The user uploads a file - I have a separate process for renaming, storing, and adding the file info to my database with express, but I will omit that for the purposes of this post</li><li>Create a read stream to pipe the contents of the CSV to an array</li><li>When the file is read, use a callback function passed as a parameter; the callback function takes the array as input and geocodes all rows asynchronously.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9792b6aa34cb79f553203bc57a86c372/href">https://medium.com/media/9792b6aa34cb79f553203bc57a86c372/href</a></iframe><p>This function was very tricky for me as I was just learning promises and asynchronous programming is a little hard to get used to, but if you have experience with promises, it should look very familiar.</p><ol><li>the very first thing we do is return the promise from the Promise.all() call. Promise.all() (<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all">MDN Docs</a>) accepts an array of promises and returns a single promise that resolves once all of the promises passed to it resolve.</li><li>Map through the passed array making a promise for each element that calls the API with the <a href="https://googlemaps.github.io/google-maps-services-js/">Node.js client</a></li><li>For this particular example I’m using a database that stores location information in two columns: primary road and secondary road. luckily I’m only trying to find the <em>intersection</em> of the roads, which the Google API can easily handle. There is an identifier called CASE_ID</li><li>we take the results from a successful <a href="https://developers.google.com/maps/documentation/geocoding/requests-geocoding">return value</a> from google and add them to a new object which we then append to an array. I also added an attribute that records if there was an error with a call to the API so that I know which row the error occurred at</li></ol><p>I then store the responses in a jsonb column in a PostgreSQL database (not shown).</p><p>Here is the full <a href="https://gist.github.com/zporteous/9ba0811f1ccd5436db3f2e52cdb78108">gist</a>. If you have installed the necessary libs and modify the column names to match your csv, you can run the file in the terminal by typing node geocode.mjs .</p><p>I’ve found this method to be extremely fast; much faster then using synchronous requests with python. If there is a different more efficient way you have done this or you see an error with the code, please reach out! Always eager to learn and refine 🙂.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aaf97e79613e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>