简体   繁体   中英

google map showing wrong map when decimal latitude and longitude is provided from mysql

I noticed that google maps does not show the correct map, when values from a mysql database having field type decimel or float are provided. varchar is accepted.

source the the browser show the correct lat and long values and no blank spaces or other issues. what ever i tried Decimal does not sohw the correct map

           $lat= $row['latitude']; (decimel from mysql, does not work)
        $long=$row['longitude'];



    $lat=15.624256;(works)
    $long=73.7943410;


   <script>
   function initialize() {
    var mapCanvas = document.getElementById('map');
    var mapOptions = {
    center: new google.maps.LatLng(<?php echo $lat.', '.$long; ?>),
      zoom: 16,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(mapCanvas, mapOptions)
  }
  google.maps.event.addDomListener(window, 'load', initialize);
</script>

Check the data. Also put enough validations to ensure you have sane coordinates and proper precision. The query should replace null with 0.

In the resulting html page, check if the html and javascript are properly formatted with the data.

Write a dummy php to know the data

$lat= $row['latitude'];
$long=$row['longitude'];
echo '<p>'.$lat.','.$long.'</p>'

TIP: Preferably avoid $long variable name. Use $longitude instead

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM