2021年3月19日星期五

Google Maps api does not mark the correct position on the map

I am looking for a way to display a map with position through latitude and longitude.

I use the following code:

 <!DOCTYPE html>      <html>        <head>          <title>Simple Map</title>          <script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>          <style type="text/css">            /* Always set the map height explicitly to define the size of the div             * element that contains the map. */            #map {              height: 100%;            }                  /* Optional: Makes the sample page fill the window. */            html,            body {              height: 100%;              margin: 0;              padding: 0;            }          </style>          <script>                  const lat = @json($latitud);            const lon = @json($longitud);            let map;                  function initMap() {              map = new google.maps.Map(document.getElementById("map"), {                center: { lat: lat, lng: lon },                zoom: 8,              });            }          </script>        </head>        <body>          <div id="map"></div>                <!-- Async script executes immediately and must be after any DOM elements used in callback. -->          <script            src="https://maps.googleapis.com/maps/api/js?key=MICLAVE&callback=initMap&libraries=&v=weekly"            async          ></script>        </body>      </html>  

From the search box I get the latitude and longitude as follows:

Livewire.emit ('getLatitude', place.geometry ['location']. Lat ());  Livewire.emit ('getLength', place.geometry ['location']. Lng ());  

Latitude and longitude I get it through Google SearchBox I save the values ​​and pass them in the variables:

const lat = @json($latitud);  const lon = @json($longitud);  

These values ​​have already been verified and they are fine.

The problem is that it takes me to the place but in an enlarged way, for example if I want to show a neighborhood, it shows me the entire city.

enter image description here

Can you please give me your help, I already looked everywhere and I can't find the reason.

https://stackoverflow.com/questions/66717911/google-maps-api-does-not-mark-the-correct-position-on-the-map March 20, 2021 at 11:19AM

没有评论:

发表评论