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
nicloznicloz 

Google Map (Lat and Long) Visual Force

Dears

 

Please could you help me with this issue?  I integrate a google map that display the latitude and longitude after the user click over the map, I can see the javascript alert witht the lat and long but I don't know how to display this value in a custom field e.g name fiel "latitud_prueba__c" , and I have a issue with "addOverlay", If I can display only the value in that field is ok, is the most important to me.

 

Let me explain the procedure:

1) I create a Visual Force page in Development section

2) Then in Customize and add to the Contact layout the page created before in a ne section with all the standar field of this module (Contact) and personalized fields for example latitud_prueba__c.

3) Then I go to module Contact, select a contact and I can see the map, when I made click I can see the javascrpt aler message with the Latitude and Longitude of the map, but how to display e.g latitude in the dield latitud_prueba__c created and displayed in the contact layout.

 

Below the code

 

 

<apex:page standardController="contact">

 <html>
  <head>
    <script type="text/javascript"
            src="http://www.google.com/jsapi?key=ABQIAAAAe2NFOp1WA-r3hEnPeArUrBST0mNpJvtWvmgvEdrgGXs5szHHahQf0jJpikHErriZM-CeKx3OJZgXvQ"></script>
    <script type="text/javascript">
    
    var geocoder;
    var address;
    
      google.load("maps", "2");
      google.load("search", "1");

      // Call this function when the page has been loaded
      function initialize() {
        var map = new google.maps.Map2(document.getElementById("map"));
        map.setCenter(new google.maps.LatLng(37.4419, -122.1419), 13);
        
        map.setUIToDefault();
        GEvent.addListener(map, "click", getAddress);
      geocoder = new GClientGeocoder();

      }
        function getAddress(overlay, latlng) {

      if (latlng != null) {
        address = latlng;
        geocoder.getLocations(latlng, showAddress);
      }
    }
    
     function showAddress(response) {
                
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1],
                             place.Point.coordinates[0]);
         
              
    //  alert(point);   // I can see lat y long

      if (!response || response.Status.code != 200) {

        alert("Status Code:" + response.Status.code);
      } else {
        
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1],
                            place.Point.coordinates[0]);
           
        marker = new GMarker(point);
        map.addOverlay(marker); // in this section a have an error, the code just stop and do not continue.
 
      // alert(place.Point.coordinates[1]+' resp 5 '+response.Status.code);   // display the lat y long, If I didn't comment with "//" the last line of code (map.addOverlay(marker)) I wont see this alert.
        marker.openInfoWindowHtml(
        '<b>orig latlng:</b>' + response.name + '<br/>' +
        '<b>latlng:</b>' + place.Point.coordinates[1] + "," + place.Point.coordinates[0] + '<br>' +
        '<b>Status Code:</b>' + response.Status.code + '<br>' +
        '<b>Status Request:</b>' + response.Status.request + '<br>' +
        '<b>Address:</b>' + place.address + '<br>' +
        '<b>Accuracy:</b>' + place.AddressDetails.Accuracy + '<br>' +
        '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);
      }
    }
    
 
   
      
      google.setOnLoadCallback(initialize);
    </script>

  </head>
 
  <body>
    <div id="map" style="width: 600px; height: 300px"></div>
    <div id="searchcontrol"></div>
  </body>

</html>

</apex:page>

 

 

Best Regards