Map display using marker using coding and javascript

I keep lat and lng in my database and try to show the map in my opinion. but nothing shows my code

<script>
var lat = <?php $property['LATITUDE']); ?>;
var long = <?php $property['LONGITUDE']); ?>;
var myCenter = new google.maps.LatLng(lat, long);
function initialize() {
    var map = new google.maps.Map(document.getElementById('map'), {
        center: myCenter,
        zoom: 16
    });
    var panorama = new google.maps.StreetViewPanorama(
        document.getElementById('pano'), {
            position: myCenter,
            pov: {
                heading: 34,
                pitch: 10
            }
        });
    map.setStreetView(panorama);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<div id="map" style="float:left; height:400px; width:49.5%;"></div>
<div id="pano" style="float:right; height:400px; width:49.5%;">></div>
</div>

What am I doing wrong here?

my model

function get_single_property($id)
{
    $q = $this->db->select('*')->from('properties')->where('id', $id)->get();
    $results = $q->result_array();
    return $results;
}
+4
source share
1 answer

The only problem that I see if you are lat, lng, of course, is correct that you are missing this in the database:

var lat = <?php echo json_encode($property['LATITUDE']); ?>;
var long = <?php echo json_encode($property['LONGITUDE']); ?>;

As you may know, you need to print your data if you pass it, and Javascript should accept data from php as a JSON object. so we added json_encode.

+2
source

Source: https://habr.com/ru/post/1623391/


All Articles