如何使用多个标记?此代码仅显示一个标记。
我知道我需要使用循环,但如何使用?
此代码将标记与 Google 地图上的数据库中的信息一起放置
我的问题是,一旦您将标记放在屏幕上,数据库中的其他标记就不会出现。
<?php
$connectmaps=$db->prepare("select title,longt,latit,description from pages where onmap = 1");
$connectmaps->execute();
$loadmaps=$connectmaps->fetch(PDO::FETCH_ASSOC);
$loadmap_json = json_encode($loadmaps);
?>
<script>
jQuery(function ($) {
// Google Maps
var script = document.createElement('script');
script.src = "http://maps.googleapis.com/maps/api/js?sensor=false&callback=initialize&key=MY_GOOGLE_MAPS_API_KEY";
document.body.appendChild(script);
});
function initialize() {
var map;
var bounds = new google.maps.LatLngBounds();
var mapOptions = {
mapTypeId: 'roadmap'
};
// Sayfada Haritayı Göster
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
map.setTilt(45);
// Multiple Markers
var phpden = <?php echo $loadmap_json; ?>;
var longt= parseFloat(phpden.longt)
var title= phpden.title
var description = phpden.description
var boylam = parseFloat(phpden.latit)
var markers = [
[title, longt, latit],
];
// İnfo Windows
var infoWindowContent = [
['<div class="info_content">' + '<h3>' + title+ '</h3>' + '<p>' + description + '</p>' + '</div>' + ''],
];
// Show multiple markers
var infoWindow = new google.maps.InfoWindow(), marker, i;
// İşaretçi Dizisini Döngüye Sok ve Harita Üzerine Yerleştir
for (i = 0; i < markers.length; i++) {
var position = new google.maps.LatLng(markers[i][1], markers[i][2]);
bounds.extend(position);
marker = new google.maps.Marker({
position: position,
map: map,
title: markers[i][0]
});
MM们
慕哥6287543
相关分类