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.
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.