Select to view content in your preferred language

"Unexpected token '<', \"<!DOCTYPE \"... is not valid JSON" WHILE using locator.addressesToLocations

1106
2
08-09-2023 02:00 AM
AkshayKumar1
New Contributor

Hi All,

I am geocoding a bunch of addresses via locator.addressesToLocations and receiving the exception "Unexpected token '<', \"<!DOCTYPE \"... is not valid JSON" in return, the geocoding service I am using is the World server i.e. https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer.

However if I run the other method addressToLocations for single address then it is working fine.  I am also using my apiKey as well. Any help provided will be appreciated.

0 Kudos
2 Replies
ReneRubalcava
Frequent Contributor II

Do you have a code sample, like with codepen or stackblitz, or github? Are you setting the esri/config apiKey? The geocode-api service requires an api key used as a token in the ArcGIS Map SDK for JS.

https://developers.arcgis.com/documentation/mapping-apis-and-services/geocoding/services/geocoding-s...

0 Kudos
AkshayKumar1
New Contributor

Here is the code and yes I am using apiKey as well:

<html>

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>ArcGIS Maps SDK for JavaScript Tutorials: Find places</title>
    <style>
        html,
        body,
        #viewDiv {
            padding: 0;
            margin: 0;
            height: 100%;
            width: 100%;
        }
    </style>
    <link rel="stylesheet" href="https://js.arcgis.com/4.27/esri/themes/light/main.css" />
    <script src="https://js.arcgis.com/4.27/"></script>

    <script>

        require(["esri/config", "esri/Map", "esri/views/MapView", "esri/rest/locator", "esri/Graphic"], function (
            esriConfig,
            Map,
            MapView,
            locator,
            Graphic
        ) {
            esriConfig.apiKey = "*****************************_en8Un6e2B9Bsb9JKDDlJ8e1MPLSmDUN6RdcilmDTsdz******";


            const map = new Map({
                basemap: "arcgis-light-gray"
            });

            const view = new MapView({
                container: "viewDiv",
                map: map,
            });

            const manyaddresses = [{
                "OBJECTID": 0,
                "Single Line Input": "77 Main St, Plymouth, NH 03264"
            }];

            const params = {
                addresses: manyaddresses,
                outFields: ["*"]
            };


            const collection = [];

            locator.addressesToLocations(locatorUrl, params).then((res) => {
                // prints the total count to the console
                console.log(res);
                // //const obj = res[0].attributes;
                // Object.keys(obj).forEach(function (key) {
                //     var object = {};
                //     object[key] = obj[key];
                //     //collection.push(object);
                //     //console.log(key, obj[key]);
                // });
                // //console.log(collection);

            });



        });
    </script>

</head>

<body>
    <div id="viewDiv"></div>
    <form id="myForm">
        <input type="file" id="csvFile" accept=".csv" />
        <br />
        <input type="submit" value="Submit" />
    </form>
</body>

</html>
0 Kudos