function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Stéphane DEMAISONStéphane DEMAISON 

Visualforce Google API Error (it worked before).

Hi Experts,

From more than 1 year and half now, we have implemented a visualforce page on the Account object, (Google API) to display on Google maps the adress of the Account.
Custom fields are used (Adress, Zip Code, City & Country (picklist).
It works properly.
2 days ago, after opening an account file, an error message has been displayed (in french) "Petit problème... Une erreur s'est produite
Google Maps ne s'est pas chargé correctement sur cette page. Pour plus d'informations techniques sur cette erreur, veuillez consulter la console JavaScript".
The map is displayed about 3 seconds and then the error message replace the map.

Hereafter the code :
 <apex:page standardController="Account">

<head>
<script src="https://maps.googleapis.com/maps/api/js?v=3&sensor=false"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
 
$(document).ready(function() {
   
  var myOptions = {
    zoom: 15,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    mapTypeControl: false
  }
   
  var map;
  var marker;
  var geocoder = new google.maps.Geocoder();
  var address = "{!Account.Address_1__c}, " + "{!Account.City__c}, " + "{!Account.Zip_Code__c}, " + "{!Account.Country__c}";
  var infowindow = new google.maps.InfoWindow({
    content: "<b>{!Account.Name}</b><br>{!Account.Address_1__c}<br>{!Account.City__c}, {!Account.Zip_Code__c}<br>{!Account.Country__c}"
  });
 
  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
      
        map.setCenter(results[0].geometry.location);
      
        //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() {
          infowindow.open(map,marker);
        });
        google.maps.event.addListener(infowindow, 'closeclick', function() {
          map.setCenter(marker.getPosition());
        });
      }
    } else {
      $('#map').css({'height' : '15px'});
      $('#map').html("Oops! {!Account.Name}'s address could not be found, please make sure the address is correct.");
      resizeIframe();
    }
  });
  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";
      }
    }
  }
});
</script>
<style>
#map {
  font-family: Arial;
  font-size:12px;
  line-height:normal !important;
  height:400px;
  background:transparent;
}
</style>
</head>
<body>
<div id="map"></div>
</body>
</apex:page>

When I look in Javascript console it's indicated the day quota of 25000 map loading is outpassed.
It's very strange, I have disabled the visualforce component in the layout in our production org, and check on our Sandbox (1st connexion of the day) and I have the same message.

Thanks in advance for your assistance.

Best regards

Best Answer chosen by Stéphane DEMAISON
LBKLBK
Recent changes in Google Map API seems to require the end user to provide the API key for this.

Replace the following line of the code
 
<script src="https://maps.googleapis.com/maps/api/js?v=3&sensor=false"></script>
with this.
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY"></script>
Replace the text YOUR_API_KEY with your actual API key.

You need to register with Google for that.

Refer https://developers.google.com/maps/documentation/geocoding/get-api-key for more information on this Key.

All Answers

LBKLBK
Recent changes in Google Map API seems to require the end user to provide the API key for this.

Replace the following line of the code
 
<script src="https://maps.googleapis.com/maps/api/js?v=3&sensor=false"></script>
with this.
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY"></script>
Replace the text YOUR_API_KEY with your actual API key.

You need to register with Google for that.

Refer https://developers.google.com/maps/documentation/geocoding/get-api-key for more information on this Key.
This was selected as the best answer
Stéphane DEMAISONStéphane DEMAISON
Thanks a lot LBK, it works now !!!