Google Maps Iframe is not showing the location marking

Asked

Viewed 1,005 times

1

There’s a part on my site where there’s a select with several places in Brazil. When selecting a place, just below has a iframe with Googlemaps that automatically updates to the coordinate corresponding to the selected location.

The problem is that some coordinates don’t appear right. The location indicated is different from the correct one, maybe because the location is not registered in Google or because it was not really mapped.

In some cases it even shows the correct area of the location, but without any markup. Example:

inserir a descrição da imagem aqui

There should be a marker in the middle of this brown terrain.

The code for the iframe that I’m using is this:

<iframe width="734" height="302" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?ie=UTF8&amp;hq=&amp;hnear=&amp;t=m&amp;iwloc=A&amp;ll=COORDENADA_AQUI&amp;spn=0,0&amp;output=embed"></iframe>

Would anyone have a solution to that? I thought I’d use the API maps to generate the codes, but since they are several places (approx. 10), it could generate some conflict or it would be difficult to rescue the coordinates from the database to insert them to the javascript.

2 answers

1

Let’s see if I understand, what you need is to put several dots on the map and set the zoom for the user to view all?

If I got it right, you can use the Google Maps API. I applied something in this direction to load customer references. In my case, I did it this way:

Javascript

$.ajax({
      type: "POST",
      data: {MODULO: "<?=$_POST["MODULO"]?>", TELA:"<?=$_POST["TELA"]?>", LATSUL: ne.lat(), LNGSUL: ne.lng(), LATNORTE: sw.lat() , LNGNORTE: sw.lng()},
      url: urlBase + "/principal.php?ACAO=CarregarReferencias",
      success: function(result){
        dadosMapa = mapa.data.addGeoJson(JSON.parse(result)); 
        mapa.data.setStyle(function(feature) {
            return {icon:"<?php echo URLBASE; ?>Imagens/referencePoint.png",title: feature.getProperty("nome")};
        }); 
      },
       beforeSend: function(){
           $(".clCarregando").show();
       },
       complete: function(msg){
           $(".clCarregando").hide();
           QtdReferencias = dadosMapa.length;
            $("#spnQtdRef").html(QtdReferencias);
       }
    });

And in PHP I searched the database for my references:

public function CarregarReferencias($ClienteId, $LatSul, $LngSul, $LatNorte, $LngNorte) {
    if ($LatSul < $LatNorte){
        $whereLat = "AND R.Latitude BETWEEN {$LatSul} AND {$LatNorte}";
    } else {
        $whereLat = "AND R.Latitude BETWEEN {$LatNorte} AND {$LatSul}";
    }

    if ($LngSul < $LngNorte){
        $whereLng = "AND R.Longitude BETWEEN {$LngSul} AND {$LngNorte}";
    } else {
        $whereLng = "AND R.Longitude BETWEEN {$LngNorte} AND {$LngSul}";
    }

    $sql = "SELECT R.Latitude AS LAT, R.Longitude AS LNG, R.Descricao AS REFERENCIA
    FROM Referencias RC
    INNER JOIN Referencias R ON (RC.ReferenciasId = R.ReferenciasId)
    WHERE ClienteId = {$ClienteId} AND R.Latitude <> 0 AND R.Longitude <> 0  $whereLat  $whereLng and R.status > 0";
    $this->bd->Clear ();
    $this->bd->setSQL ( $sql );

    $tmp = '{"type": "FeatureCollection","features": [';
    if ($this->bd->Executar ()) {               

        foreach ( $this->bd->Registro as $registro ) {
            $tmp.='{ "type": "Feature", "geometry": { "type": "Point",  "coordinates": [ '. $registro->Campo ["LNG"] .', '. $registro->Campo ["LAT"] .' ]}, "properties": { "nome": "'. str_replace("'", '`', str_replace('"', '`', $registro->Campo ["REFERENCIA"])) .'" } },';
        }
        $tmp = substr($tmp, 0, -1);

    } 
    $this->Lista = $tmp.']}';
    $this->Lista = json_decode($this->Lista);
    return true;
}
  • Well, an alternative would be to record all the locations on the same map, and when you select the location, it goes to the corresponding marking. The problem is that when you choose the location on select, the content block gives a refresh, as in addition to showing the map, the location information is listed..

0


Browser other questions tagged

You are not signed in. Login or sign up in order to post.