我有一个magento网站,我的产品是企业。 我想添加一个谷歌地图到产品页面,需要有人来帮助我使用我的代码。取得属性(邮政编码),并在Google地图API中使用它3
我可以通过键入
<?php echo $_product->getpostcode() ?>
我从网上取码,我试图把它一起为我的网站调用邮政编码。这里是代码:
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script>
var geocoder;
var map;
var address = '<?php echo $_product->getpostcode() ?>'
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
}
function codeAddress() {
var address = document.getElementById('address').value;
geocoder.geocode({ 'address': address}, 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);
}
});
}
</script>
<body onload="initialize()">
<div id="map_canvas" style="width: 500px; height: 300px"></div>
目前它正在使用中的代码纬度长。我怎样才能改变它使用的邮政编码?`
嗨安德鲁,我怎么能地址添加到全局变量?目前我可以通过输入以下命令获得邮政编码<?php echo $ _product-> getpostcode()?>我按照你的指示,在地图显示悉尼时。我认为这是从我的代码中的长和经度数字 – user1564305 2012-07-31 13:06:14
Works for me:http://jsfiddle.net/acleach/73Pf6/(使用伦敦邮政编码而不是您的任何PHP输出)。地理编码将正常工作并重新设置地图,否则它将输出失败消息并显示“mapOptions”位置,这确实是悉尼地区。 – 2012-07-31 13:12:46
嗨安德鲁,看起来像我到达那里。当我手动输入邮政编码时,它也适用于我。正如我之前提到的,我将从php echo命令中获取邮政编码。我现在需要把它放到var地址中。当我尝试这样做时,由于以下原因,我得到Geocode不成功Zero_results – user1564305 2012-07-31 13:33:48