Gimana cara memperbaiki undefined variable dan trying to get property of non-object

File location_model.php : function get_saved_locations(){ $indexed = array("type"=>"FeatureCollection","features"=>array()); $con=mysqli_connect ("localhost", 'root', '','marketingdansales2'); if (!$con) { die('Not connected : ' . mysqli_connect_error()); } // update location with location_status if admin location_status. $sqldata = mysqli_query($con,"SELECT existing.kd_ex, existing.kd_cust, existing.kd_jns_layanan, nm_cust, longitude, latitude, nm_jns_layanan, sid, bw, pa_number, harga_sewa, service_status FROM cust, existing, jns_layanan WHERE cust.kd_cust=existing.kd_cust AND existing.kd_jns_layanan=jns_layanan.kd_jns_layanan"); $rows = array(); while($r = mysqli_fetch_assoc($sqldata)) { $rows[] = $r; } $saved_markers = array_map(function($rows){ return array( "type"=>"Feature", "geometry"=>array( "type"=>"Point", "coordinates"=>array($row->longitude,$row->latitude)), "properties"=>array( "EX"=>$row->kd_ex, "CS"=>$row->kd_cust, "JL"=>$row->kd_jns_layanan, "NM"=>$row->nm_cust, "SID"=>$row->sid, "BW"=>$row->bw, "PA"=>$row->pa_number, "NJL"=>$row->nm_jns_layanan, "HS"=>$row->harga_sewa, "SS"=>$row->service_status ) ); },$rows); // $array = array_filter($indexed); $indexed["features"] = $saved_markers; echo json_encode($indexed); if (!$rows) { return null; } } File Index.php : var saved_markers = <?= get_saved_locations() ?>; JSON.parse(saved_markers); var marker ; map.on('load', function() { add_markers(saved_markers); }); function add_markers(coordinates) { var geojson = (saved_markers == coordinates ? saved_markers : ''); console.log(geojson); // add markers to map geojson.features.forEach(function (marker) { var el = document.createElement('div'); el.className = 'marker'; console.log(marker); // make a marker for each feature and add to the map new mapboxgl.Marker(el) .setLngLat(marker.geometry.coordinates) .setPopup(new mapboxgl.Popup({ offset: 25 }) .setHTML('

' + marker.properties.SID + '

' + marker.properties.NM + marker.properties.NJL + marker.properties.HS + marker.properties.SS '

')) .addTo(map); }); }
avatar Renaldi30

Ditanyakan oleh @Renaldi30

2 Kontribusi 0 Poin

  • bungkus kodingan dengan tag kode bisa rapi - @dianarifr

Login untuk menanggapi


Jawaban

Mohon bantuannya master master ngoding bagi ilmunya
avatar Renaldi30

Dijawab oleh @Renaldi30

2 Kontribusi 0 Poin

Login untuk menanggapi


Login untuk gabung berdiskusi