Google map issue

Discussion in 'Templates, HTML, CSS, and Design Help' started by jason1971, Dec 30, 2014.

  1. jason1971 Customer

    Hi all,

    I am trying (in vain) to add a zoomable Google map to my advert listings page (viewlisting.tpl) using a postcode (zip code) added by my advertisers using an extra field. However, when I insert the extra field in to the code and test it, it says "Geocode was not successful for the following reason ZERO_RESULTS"

    {literal}<script src="http://maps.googleapis.com/maps/api/js?key=MYAPIKEY&sensor=false" type="text/javascript"></script>{/literal}
    {literal} <script>
    var geocoder;
    var map;
    function initialize() {
    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var mapOptions = {
    zoom: 14,
    center: latlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
    codeAddress();
    }

    function codeAddress() {
    var address = '{get_extra_field id=$view fid=14}';
    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);
    }
    });
    }

    google.maps.event.addDomListener(window, 'load', initialize);
    </script>{/literal}

    <div id="map-canvas" style="width:100%;height:300px;"></div>



    any thoughts on either what I am doing wrong or what is missing ??????

    Cheers

    Jason.
  2. Mike-N-Tosh Owner

    I can't say for sure, but I imagine you are not getting results because the extra field is within the javascript which is within the "{literal}{/literal}" which is telling Smarty, "DO NOT PROCESS THIS!"

    I would suggest getting out of "{literal}", something like this:
    Code:
    var address = '{/literal}{get_extra_field id=$view fid=14}{literal}';
    You can see examples of this in several template files that have javascript within them, such as forms (javascript validation), etc..
  3. jason1971 Customer

    Mike,

    What can I say... it worked like a charm

    Thanks soooooooooooooooooooooooo much

Share This Page