SyntaxError:在navigator.geolocation.getCurrentPosition.enableHighAccuracy中输入意外结束

问题描述 投票:0回答:2

我在响应本机中进行反向地理编码(从lat和lon获取地址)时遇到此错误。

请让我知道是否有任何建议

发生实际错误

SyntaxError:在MessageQueue处navigator.geolocation.getCurrentPosition.enableHighAccuracy(blob:http://localhost:8081/23c307eb-648d-4fee-b83d-d0a4187bcffe:314435:22)处的输入意外结束。在MessageQueue .__ blob:http://localhost:8081/23c307eb-648d-4fee-b83d-d0a4187bcffe:2635:18处的__invokeCallback(blob:http://localhost:8081/23c307eb-648d-4fee-b83d-d0a4187bcffe:2366:18)。__guard(blob:http://localhost:8081/23c307eb-648d-4fee-b83d-d0a4187bcffe:2539:13 ),位于http://localhost:8081/23c307eb-648d-4fee-b83d-d0a4187bcffe:2365:14]的MessageQueue.invokeCallbackAndReturnFlushedQueue(blob:http://localhost:8081/debugger-ui/debuggerWorker.js:80:58

并且我的代码在下面

fetch(
          `${
            MY URL
          }?key=${googleLocationAPIKey}&latlng=${lat +
            "," +
            long}`
        )
          .then(resp => resp.json())
          .then(data => {
            console.warn("data", data);
            if (data && data.results && data.results.length) {
              const result = data.results[0];
              var region =  {
                latitude: result.geometry.location.lat,
                longitude: result.geometry.location.lng,
                formatted_address: result.formatted_address,
                latitudeDelta: LATITUDE_DELTA,
                longitudeDelta: LONGITUDE_DELTA
              }
              that.setState({
                region
              });
            }
          })
          .catch(err => {
            //this.getCurrentLocation()
            console.log(err.message);
          });

调试时显示错误然后(resp => resp.json())

来自resp

从早上尝试过,但是没有运气,请让我知道任何建议

我在响应本机中得到反向地理编码(从lat和lon获取地址)的错误。请让我知道是否有任何建议实际错误在SyntaxError之后:...的意外结尾...]]

google-maps react-native geocoding
2个回答
0
投票
这不像是与react native的编码部分相关...我根据Google的建议在API密钥中添加了一些限制。这就是为什么此错误来自API的原因,现在我已经删除了限制并重新加载了应用程序..现在它可以正常工作。

-1
投票
更改

that.setState({region});

© www.soinside.com 2019 - 2024. All rights reserved.