简体   繁体   中英

Mapbox center and set appropriate zoom level for a country

I'm trying to find a way to center and zoom to a country using Mapbox. I am able to get a country its coordinates using the geocoder, however, the zoom levels differ per country. (Eg the zoom level for Spain is not the same level for the USA)

function showMap(err, data) {

        console.log(data);
        console.log(err);

        if (err == true) {
            console.log("Couldn't find this place!");
        } else {
            map.fitBounds(data.lbounds);        
        }   

}   


var geocoder = L.mapbox.geocoder('x',map);

geocoder.query("Spain", showMap);

Would I need an additional layer with fusion tables to achieve this?

Thanks for any help!

Can you be much more specific with this question, and provide an example, preferably something you can link to, with full code?

I am able to get a country its coordinates using the geocoder, however, the zoom levels differ per country.

The usage of 'however' is confusing: large countries will have different zoom levels than small. Is this what you see happening? Or not? Is this something you desire, or not?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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