You need to sign in to do that
Don't have an account?
Benzy
Coordinates in Visualforce map results in different location to Google maps
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
Visualforce Page Map
(you can see the coordinates returned from the apex class just above the map - these are what the map is using.)
Google Map
(notice coordinates are the same as the VF page, but pin location is different)
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.)
Google Map
(notice coordinates are the same as the VF page, but pin location is different)
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.
All Answers
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.
That worked perfectly.
Thanks, Bjoern