• Hello,

    I’m working with ACF Openstreetmap Field on a client website.

    I enter an address in the administration (let’s take “Route de Cruciata, 20166 Pietrosella, France Corse”) and when I zoom on the map, everything is fine, I’ve got something like this position : 41.8440158, 8.7823428.

    But when I display the map on the website, with datas, I’ve got an address somewhere not far, but not on the exact point (like 500m away : 41.8368279,8.7780762).

    When I look at the lng and lat values, they are already wrong. Something happens between the save in the administration and the recovery of the data in my file.

    Here is part of my code :

      jQuery(document).ready(function($){
    
                        var zoomvalue = 4.8;
                        var largeurf = $(window).width();
    
                        if(largeurf >=768){ zoomvalue = 5.4;}
                        if(largeurf >=992){ zoomvalue = 5.5;}
                        if(largeurf >=1200){ zoomvalue = 5.6;}
    
    
    //                    console.log(zoomvalue);
                        //Initialisation de la carte sur Londres
                        var map = L.map('carte-programmes').setView([46.5177483, 0.6572277], zoomvalue); // LIGNE 18
    
                        //Ajout du fond de carte
                        var Jawg_Streets = L.tileLayer('https://{s}.tile.jawg.io/jawg-sunny/{z}/{x}/{y}{r}.png?access-token={accessToken}', {
                            minZoom: 0,
                            maxZoom: 22,
                            subdomains: 'abcd',
                            accessToken: 'XXXX (hidden on purpose)'
                        });
                        map.addLayer(Jawg_Streets);
    
                        //Mise en place des clusters et du CSS des clusters
                        var markersCluster = new L.MarkerClusterGroup({
                            iconCreateFunction: function(cluster) {
                                return L.divIcon({
                                    html: cluster.getChildCount(),
                                    className: 'mycluster',
                                    iconSize: null
                                });
                            }
                        });
    
                        //Customise les icones de marqueur au zoom
                        var customIcon = L.icon({
                            iconUrl: '<?php print $img;?>marker.png',
                            shadowUrl: '<?php print $img;?>marker-shadow.png',
                            iconSize:     [64, 64], // taille de l'icone
                            shadowSize:   [64, 64], // taille de l'ombre
                            iconAnchor:   [32, 64], // point de l'icone qui correspondra à la position du marqueur
                            shadowAnchor: [32, 64],  // idem pour l'ombre
                            popupAnchor:  [-3, -76] // point depuis lequel la popup doit s'ouvrir relativement à l'iconAnchor
                        });
                        L.Marker.mergeOptions({
                            icon: customIcon
                        });
    
    
                        //Prépare tous les marqueurs correspondants aux programmes et génère les popups
                        <?php foreach($idsprog->posts as $idprog):?>
                        var latLng = new L.LatLng(<?php print get_field('adresse',$idprog)['lat'];?>,<?php print get_field('adresse', $idprog)['lng'];?>);
    					
                        var marker = new L.Marker(latLng);
    					
    					
                        marker.bindPopup(
                            '<a href="<?php the_permalink($idprog);?>" class="produit popup_carte">' +
                            '<div class="visuel">' +
                            '<img src="<?php print get_field('vignette',$idprog)['sizes']['330x200'];?>" />' +
                            '<div class="textes-visuel">' +
                            '<div class="type"><?php foreach(get_field('type_logement',$idprog) as $type):?><?php print $type;?><span class="slash"> / </span><?php endforeach;?></div>'+
                            '<div class="livraison">Livraison <?php print (get_field('annee_livraison',$idprog) > 1) ? the_field('annee_livraison',$idprog) : 'immédiate';?></div>' +
                            '</div>' +
                            '</div>' +
                            '<div class="textes">' +
                            '<h4><?php print get_the_title($idprog);?></h4>' +
                            '<div class="lieu"><?php print addslashes(get_term(get_field('lieu',$idprog), 'lieux')->name);?></div>' +
                            <?php if( have_rows('prix',$idprog) ): the_row();?>
                            '<div class="prix">à partir de <?php print preg_replace('/(?<=\d)(?=(\d{3})+$)/', ' ', trim(get_sub_field('prix_prog',$idprog)));?>€</div>' +
                            <?php endif;?>
                            '</div>' +
                            '</a>'
                        );
                        markersCluster.addLayer(marker);
                        <?php endforeach;?>
    
                        map.addLayer(markersCluster);
    
    
                    });

    Thank you for your help. The website seemed to work since 2-3 years but now there is this problem, I don’t know if it’s really new or if we missed it, but it would be odd that I didn’t saw it earlier…

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Position change between ACF Field and display on the front’ is closed to new replies.