Using VF i am displaying google map based on geolocation field which is a formula field(Lat_Long_Values__c) contain latitude and longitude value. When i run this VF page if there is no value in geolocation field it is throwing an error message but when i checked this under Account record it is not throwing an error message if there is no value in geolocaiton field. How to display the error message here i have attahced the VF code.

enter image description here enter image description here

<apex:page standardController="Account" >
<apex:pageBlock >

<script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> 
<script type="text/javascript"> 

$(document).ready(function() {

  var myOptions = {
    zoom: 20,
    mapTypeId: google.maps.MapTypeId.HYBRID,
    mapTypeControl: true

  var map;
  var marker;

  var geocoder = new google.maps.Geocoder();
<!--var address =  "{!Account.BillingStreet}, {!Account.BillingPostalCode} {!Account.BillingCity}, {!Account.BillingState},{!Account.BillingCountry}"; -->

   <!-- //var address =  "{!Account.Latitude__c}, {!Account.Longitude__c} ";  -->
     var address = "{!Account.Lat_Long_Values__c}";

  var infowindow = new google.maps.InfoWindow({
    content: "<b>{!Account.Lat_Long_Values__c}</b>"
 <!--  content: "<b>{!Account.BillingStreet} {!Account.BillingPostalCode} {!Account.BillingCity}, {!Account.BillingState},{!Account.BillingCountry}</b>"-->

  geocoder.geocode( { address: address}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK && results.length) {
      if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {

        //create map
        map = new google.maps.Map(document.getElementById("map"), myOptions);

        //center map

        //create marker
        marker = new google.maps.Marker({
            position: results[0].geometry.location,
            map: map,
            title: "{!Account.Name}"

        //add listeners
        google.maps.event.addListener(marker, 'click', function() {
        google.maps.event.addListener(infowindow, 'closeclick', function() {
        google.map.setOptions({streetViewControl: false});


    } else {
      $('#map').css({'height' : '15px'});
      $('#map').html("Oops! {!Account.Name}'s address could not be found, please make sure the address is correct.");

  function resizeIframe() {
    var me = window.name;
    if (me) {
      var iframes = parent.document.getElementsByName(me);
      if (iframes && iframes.length == 1) {
        height = document.body.offsetHeight;
        iframes[0].style.height = height + "px";


#map {
  font-family: Arial;
  line-height:normal !important;


<div id="map"></div> 
  • Not clear what's your exact problem. Your problem is "how to display an error message" or "google map not showing correctly"? – highfive Jun 17 '14 at 5:13
  • thanks for reply highfive how to display an error message under the Account record. – user7292 Jun 17 '14 at 6:02
  • The apostrophe mark after the {!Account.Name} in line $('#map').html("Oops! {!Account.Name}'s address... may breaking your code. Try escaping special characters; i.e $('#map').html("Oops! {!Account.Name}\'s address... – highfive Jun 17 '14 at 6:09
  • Hi Highfive i have removed {!Account.Name}'s and run a code it showing empty map instead of displaying error message like the screen shots i updated above. – user7292 Jun 17 '14 at 6:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.