我有一个 magento 网站,我的产品是企业。我想将谷歌地图添加到产品页面,需要有人帮助我编写代码。
我可以通过键入来拨打邮政编码
<?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>
目前它在代码中使用 lat long。我怎样才能将其更改为使用邮政编码?`