简体   繁体   English

未定义MapboxGeocoder反应no-undef

[英]react MapboxGeocoder is not defined no-undef

Everything was alright but suddenly I got this error. 一切都很好,但是突然我得到了这个错误。 I have googled many times but no solution. 我已经搜索过很多次,但没有解决方案。 Can anybody help me out, please? 有人可以帮我吗? 在此处输入图片说明

Code I have used 我使用的代码

import React, { Component } from 'react';
import MapboxGl from 'mapbox-gl/dist/mapbox-gl';
import '../App.css';

class MapContent extends Component {

    componentDidMount() {
        MapboxGl.accessToken = ACCESS_TOKEN;

        var map = new MapboxGl.Map({
            container: this.Mapcontainer,
            style: 'mapbox://styles/mapbox/streets-v9',
            center: [-74.50, 40], // starting position
            zoom: 9 // starting zoom
        });

        var geocoder = new MapboxGeocoder({
            accessToken: MapboxGl.accessToken
        });

        map.addControl(geocoder);
    }

    render() {
        return (
            <div className='MapContent' ref={(x) => { this.Mapcontainer = x }}>
            </div>
        )
    }
}

export default MapContent;

Got the answer. 得到了答案。 I must install '@mapbox/mapbox-gl-geocoder' . 我必须安装'@mapbox/mapbox-gl-geocoder' Just type 只需输入

npm install @mapbox/mapbox-gl-geocoder --save npm install @ mapbox / mapbox-gl-geocoder-保存

MapboxGeocoder will work well then. 这样,MapboxGeocoder将会运行良好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM