bozdoz / wp-plugin-leaflet-map

Add leaflet maps to Wordpress with shortcodes
https://wordpress.org/plugins/leaflet-map/
GNU General Public License v2.0
140 stars 71 forks source link

Default settings match user culture and create undefined properties #203

Closed Lus0rius closed 1 year ago

Lus0rius commented 1 year ago

Hi,

I believe it is not intended that settings match the user's culture. For example, in French, the separator between the unit and the decimals is a , not a . So even if i write a dot in the "Default latitude" setting, it gets converted to a comma.

At the same time, I get an error "Warning: Undefined property: stdClass::$lat in /home/clients/.../sites/wp-content/plugins/leaflet-map/class.geocoder.php on line 70", and the same for longitude.

bozdoz commented 1 year ago

That is an interesting problem. How can I test this?

hupe13 commented 1 year ago

I have german and english sites and I can confirm this: Even if I enter values for the default settings with a dot on the settings page, they are displayed with a comma on german sites. In the database the values are stored with a dot. When I write the values with a comma [leaflet-marker lat=0,0 lng=0,7]default[/leaflet-marker], I get a TypeError. But I have never seen the geocoder error. When does it occur?

Lus0rius commented 1 year ago

After further testing, the geocoder error comes from a marker whose address is not found. The default longitude and latitude values are taken into account even if they contain commas (like hupe13 said, they must be stored internally with a dot). Sorry about that useless thread.

hupe13 commented 1 year ago

the geocoder error comes from a marker whose address is not found

This is actually fixed. But that does not seem to be the case. I have not tested properly, I'm sorry @bozdoz.

hupe13 commented 1 year ago

https://github.com/bozdoz/wp-plugin-leaflet-map/blob/5e524873bb64602e4976fc89fe4c35b0f41f5777/class.geocoder.php#L70-L71

should be:

if (isset($location->lat) && isset($location->lng)) {
   $this->lat = $location->lat;
   $this->lng = $location->lng;
}

or similar. Then the not found marker is on 0,0.

bozdoz commented 1 year ago

@hupe13 is that all that needs changing?

hupe13 commented 1 year ago

Yes, I just tested it again. The marker then appears at the null point [0, 0] because of https://github.com/bozdoz/wp-plugin-leaflet-map/blob/93bb4d9ff89673d9e1036dc3d0bb29cbdbcea543/class.geocoder.php#L14