Skip to main content The Trailblazer Community will be unavailable from 2/1/2025 to 2/2/2025. Please plan your activities accordingly.
error

We made a wrong turn. Try again.

I am using the apex:map component in a Visualforce page. I can successfully render a map using coordinates pulled through an apex class.

However, the resulting location on the Visualforce page is slightly different to that shown if I put the same coordinates directly into Google Maps. (See maps below)

Does anyone know why this is happening?

VF page map code

 

<!-- Display the address on a map -->

<apex:map width="600px" height="400px" mapType="roadmap" zoomLevel="17" center="{!program.Location__r.LatitudeTEXT__c},{!program.Location__r.LongitudeTEXT__c}">

<apex:mapMarker title="" position="{!program.Location__r.LatitudeTEXT__c},{!program.Location__r.LongitudeTEXT__c}"/>

</apex:map>

Visualforce Page Map

(you can see the coordinates returned from the apex class just above the map - these are what the map is using.)

User-added image

Google Map

(notice coordinates are the same as the VF page, but pin location is different)

User-added image
3 answers
  1. May 13, 2015, 3:56 PM
    Hi Benzy,

    If you already have the coordinates for the location you're interested in, you should pass them as string that represents a JSON object with 'latitude' and 'longitude' attributes that specify location coordinates. For example, in your case it should be:

    center="{latitude: 17.415886, longitude: 78.405906}",        not center="17.415886, 78.405906" as you have it now.

    Another option is to use an Apex map object of type Map<String, Double>, with 'latitude' and 'longitude' keys. When you use just comma separated coordinates, the string is treated as an address string and is geocoded to determine actual latitude and longitude. It looks like geocoding returns slightly different latitude and longitude values and this causes the behavior that you observe.

     
  2. Jul 5, 2019, 10:14 AM
    Hi, I have the same problem, but newbi here, how would the VF code from up look like?

    Thanks, Bjoern
0/9000