This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

bart57983
bart57983

Hi, The MapMarkers plugin rounds the given coordinates of a location to two digits behind the comma. This results in locations that are far from precise. It should allow at least 6 digits behind the comma. Is there a way to adapt that? Thanks in advance! Bart Devos.

mjauvin
mjauvin

Did you ask the author?

mjauvin
mjauvin

I checked the source code, and it's actually the database table definition that causes the problem:

mysql> describe graker_mapmarkers_markers;
+-------------+------------------+------+-----+---------+----------------+
| Field       | Type             | Null | Key | Default | Extra          |
+-------------+------------------+------+-----+---------+----------------+
| id          | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| title       | varchar(191)     | YES  |     | NULL    |                |
| description | text             | YES  |     | NULL    |                |
| user_id     | int(10) unsigned | YES  | MUL | NULL    |                |
| latitude    | double(8,2)      | NO   |     | NULL    |                |
| longitude   | double(8,2)      | NO   |     | NULL    |                |
| created_at  | timestamp        | YES  |     | NULL    |                |
| updated_at  | timestamp        | YES  |     | NULL    |                |
| sort_order  | int(10) unsigned | YES  |     | NULL    |                |
+-------------+------------------+------+-----+---------+----------------+
mjauvin
mjauvin

Since lat/long coorinates in google map can take the following format, I would think a string would be more suitable for the lat/long fields:

48.3976556,-71.0833616,17z

Not sure what the trailing ,17z is exactly, but if it's important, there is no easy way to represent this with a float/double...

bart57983
bart57983

Dear Mjauvin, thank you for your answer. I'll mention it to the author and do some tests myself. I will post a solution if i have one. Kind regards, Bart Devos.

bart57983
bart57983

Apparently the digits before 'z' is the elevation. I don't think this is needed for an exact location.

bart57983
bart57983

This link https://developers.google.com/maps/documentation/javascript/mysql-to-maps states that longitude and latitude may be stored as FLOAT (10,6) in MySQL.

mjauvin
mjauvin

Nice to know! I'll do some testing...

mjauvin
mjauvin

Ok, create a plugin and add a migration to it like below to fix the issue until it is resolved upstream:

use DB;
use October\Rain\Database\Updates\Migration;

class UpdateMarkersTable extends Migration
{
    public function up()
    {   
        DB::statement('ALTER TABLE graker_mapmarkers_markers MODIFY latitude FLOAT(10,6) NOT NULL;');
        DB::statement('ALTER TABLE graker_mapmarkers_markers MODIFY longitude FLOAT(10,6) NOT NULL;');
    }

    public function down()
    {   
        DB::statement('ALTER TABLE graker_mapmarkers_markers MODIFY latitude FLOAT(10,2) NOT NULL;');
        DB::statement('ALTER TABLE graker_mapmarkers_markers MODIFY longitude FLOAT(10,2) NOT NULL;');
    }
}
mjauvin
bart57983
bart57983

Dear Mjauvin, Thanks for your answers! I now came to the conclusion that it has nothing to do with the precision of the database fields. Hereafter my answer to the developer of MapMarker:

The columns latitude and longitude in mysql where initially defined as FLOAT(8,6). This setting truncated the value in the table to 5 digits (which isn't logic). I changed the column settings to DOUBLE without any additional directives. Adding directives for the number of digits before and after the comma is deprecated in MySQL 5.7 and above anyway. Now the full values are stored in the database without any truncation. So the problem isn't in the database anymore. I suspect that the values are truncated somewhere else in the code. As i'm not a php nor javascript developer i'm afraid i can not solve this problem although i'll give it a try.

And another one:

In my test case the coordinates i passed to MapMarker are 50.896041, 2.656350 (the correct values). The coordinates of the position shown by MapMarker is approx. 50.851437, 2.653625 (I had to figure it out manually). So the change of coordinates has nothing to do with precision, truncation nor rounding differences. It's somehow a misscalculation of some sort. Hope this helps.

mjauvin
mjauvin

When I change the database fields, everything works fine. Did you try my helper plugin?

mjauvin
mjauvin

When you manage the markers, do they show up at the right place on the map in backend? With my helper plugin that modifies the database, they do show at the precise location on the map.

If they don't in your case, I suggest uninstalling both plugins and starting over, as something is screwed up in your database table.

Last updated

bart57983
bart57983

I altered the table directly in MySql with your settings. I suppose your plugin doesn't do anything else than the sql query? The coordinates where already precise enough when i changed the columns to DOUBLE. So nothing changed in the database but the position is still far from accurate. See the last part of my former post. I don't think it has something to do with the precision of the stored data. I did a test directly in Google Maps and i truncated manually the coordinates step by step. Only with two digits after the comma the location starts to differ seriously. In other words: with only 3 digits after the comma, the location is only 20-30 meters out of focus. Another proof that the problem has nothing to do with the precision of the float or double data type.

mjauvin
mjauvin

I understand what you're saying, but from what I can see on the backend, the coordinates ARE precise in my case (once database has been modified).

there's nothing in the code (JavaScript or other) that truncates the precision, it was all caused by the float(8,2) in the database field definition.

mjauvin
mjauvin

I entered the coordinates you gave above, and it properly shows the location on corner of bromstraat/blasiusstraat in Belgium

bart57983
bart57983

I have no idea what happened but now the coordinates and the location are correct. And yes, i did a clear cache before reloading the page. I don't know what is changed that corrected this problem. I will test furthermore because i feel uncomfortable with the fact that i don't know the reason why it works now. Thank you for your efforts!

mjauvin
mjauvin

did you update the coordinates?? odd.

1-18 of 18

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.