Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Leaflet fitBounds bounds are not valid

czeslaw187

New Coder
So I'm trying to fitBounds on leaflet map to the desired geoJson feature. Firstly I'm returning latitude and longitude from navigator getCurrentPosition() method to use reverse geocoding and get the country name. Secondly the country name is used to extract geoJson feature from a geoJson file on my server. The returned feature is the used to draw a polygon and fitBounds and everything works fine on apache. When I upload the code on my hosting service I'm getting an error that bounds are not valid. I've tried several approaches without success.

Any ides what I'm doing wrong? Anything to do with the hosting service?

[CODE lang="javascript" title="N/a"]// get current position

navigator.geolocation.getCurrentPosition(position => {
let lat = position.coords.latitude;
let lng = position.coords.longitude

L.marker([lat, lng]).addTo(mymap);
// get current country
$.post('php/reverseGeo.php', {
lat: lat,
lng: lng
}, response => {
let name = JSON.parse(response)
let country = name['address']['country']
$.post('php/countryList.php', {
countryName: country
}, result => {
let decoded = JSON.parse(result)
let border = L.geoJSON(decoded).addTo(mymap)

console.log(border.getBounds())
mymap.fitBounds(border.getBounds())
$('#element1').slideDown()
...[/CODE]

When I log border.getBounds() to the console it returns nothing on apache it return the correct object.
 
Back
Top Bottom