我一直使用具有隻需添加座標在菜單中直接顯示聯繫人頁面在地圖的支持,一個WordPress主題2張使用不同的座標谷歌地圖。現在我有一個新的業務地址需要添加到聯繫人地圖中,但主題不支持。添加
給予的事實,我在PHP和JS的經驗是有限的我找不到我的問題的解決方案。
我的聯繫人頁面代碼是波紋管和所有我需要的是聯繫表格之前添加不同COORDS新地圖。
<div id="content">
<?php
if (have_posts()) :
while (have_posts()) :
the_post();
$show_map = get_option('theme_gmap_show');
if($show_map == 'true')
{
$map_lati = get_option('theme_gmap_lati');
$map_longi = get_option('theme_gmap_longi');
$map_zoom = get_option('theme_gmap_zoom');
?>
<div class="map-container clearfix">
<div id="map_canvas"></div>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initialize()
{
var geocoder = new google.maps.Geocoder();
var map;
var latlng = new google.maps.LatLng(<?php echo $map_lati; ?>, <?php echo $map_longi; ?>);
var infowindow = new google.maps.InfoWindow();
var myOptions = {
zoom: <?php echo $map_zoom; ?>,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
geocoder.geocode({ 'location': latlng },
function(results, status) {
if (status == google.maps.GeocoderStatus.OK)
{
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
}
else
{
alert("Geocode was not successful for the following reason: " + status);
}
});
}
initialize();
</script>
</div>
<?php
}
the_content();
$postal_address = stripslashes(get_option('theme_postal_address'));
if(!empty($postal_address))
{
?>
<h3 class="smart-head">Adresa de contact</h3>
<p><address>
<?php echo $postal_address; ?>
</address></p>
<?php
}
?>
<div class="contact-orar">
<h3 class="smart-head">Program de Lucru</h3>
<p><strong>Luni - Vineri:</strong> 8:00 - 17:00<br />
<strong>Sambata:</strong> 8:00 - 14:00<br />
<strong>Duminica:</strong> inchis</p>
</div>
<div class="contact-form-container">
預先感謝您的幫助!
此代碼無法正常工作,看起來不會從谷歌加載第二張地圖。 – 2013-03-22 16:54:55
對不起,我寫了'map-canvas_2'而不是'map_canvas_2'。我更新了代碼。請再試一次。 – user2019515 2013-03-22 18:24:28