'Cannot locate when disabled.'

685
2
Jump to solution
03-23-2023 02:28 AM
Blakearc
New Contributor II

I am using ArcGIS with react. I have successfully displayed a map and now I want to get current location once the map is loaded. I included all the setup inside a useEffect hook. I configured the location widget as below:

const locateWidget = new ArcGISLocate({
    view: view,
    useHeadingEnabled: false,
    goToOverride: function (view, options) {
        options.target.scale = 1500;
        return view.goTo(options.target);
    },
});
 
locateWidget.locate().then(function () {
    console.log("success");
});

 

 

However I got the following error return:

    details: undefined

    message: "Cannot locate when disabled."

    name: "locate:disabled-state"

 

I tried using HTTPS over HTTP but the error still exists. How to solve this problem?

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
AndyGup
Esri Regular Contributor

Hi @Blakearc most likely the View isn't ready (view.ready === false) when you try to initialize the Locate widget. If you are still having issues after looking into that, you'll need to provide a focused, working github repo, stackblitz or codesandbox example of your React project. Here a basic troubleshooting guide: https://github.com/Esri/jsapi-resources/blob/main/TROUBLESHOOTING.md#four-triage-steps.

View solution in original post

2 Replies
AndyGup
Esri Regular Contributor

Hi @Blakearc most likely the View isn't ready (view.ready === false) when you try to initialize the Locate widget. If you are still having issues after looking into that, you'll need to provide a focused, working github repo, stackblitz or codesandbox example of your React project. Here a basic troubleshooting guide: https://github.com/Esri/jsapi-resources/blob/main/TROUBLESHOOTING.md#four-triage-steps.

Blakearc
New Contributor II

Thank you for answering. I put the locate() into view.when() and it works now !

0 Kudos