You need to sign in to do that
Don't have an account?
swaarnimdev
How to build map with marker to get geolocation.
I have a simple code for getting geolocation based on address on a custom object.
I want to place the geolocation marker on map and allow the user to change the location by dragging around the marker (if its mispalced).
I want to place the geolocation marker on map and allow the user to change the location by dragging around the marker (if its mispalced).
Geocoding: https://developers.google.com/maps/documentation/javascript/examples/geocoding-simple
Once you get latitude and longitude, you can plot that location on map as a marker. Then add dragend event on marker which will allow you to get the marker drag event and eventually return you the new locations lat and lng. using this lat lng, you can get the address using reverse geocoding.
Reverse geocoding: https://developers.google.com/maps/documentation/javascript/examples/geocoding-reverse
For second requirement, As per my understanding you want to show the custom object's records which are some radius away from the current record?
For this, you will have to create geolocation field on custom object. Store latitude and longitude of custom object and then you can use geolocation query in apex where you can define radius and subject lat lng.
Geolocation soql: https://developer.salesforce.com/blogs/developer-relations/2012/10/winter-13-using-apex-and-soql-with-geolocation.html
All Answers
You can find google map documentation here https://developers.google.com/maps/documentation/javascript/3.exp/reference
Below is the sample code.
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initialize() {
var mapDiv = document.getElementById('map-canvas');
var map = new google.maps.Map(mapDiv, {
center: new google.maps.LatLng(37.4419, -122.1419), // set the center same as your custom object location or any point you want
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var marker = new google.maps.Marker({
map: map,
position: new google.maps.LatLng(37.4419, -122.1419), // set the marker lat lng as your custom object location
draggable: true
});
// Add listner to drag end event
google.maps.event.addListener(marker, 'dragend', function(evt){
// You can access the lat lng where marker is dropped though evt as shown below
// You can call actionfunction here and pass this information and save it to the custom object field
alert('Latitude: '+evt.latLng.lat()+ ' & Longitude'+evt.latLng.lng());
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
You can also try your google map code in google playground
https://code.google.com/apis/ajax/playground/#draggable_marker_v3
What customization you want to achieve?
Secondly in searching records same will be applied with a marker and radius (dynamically changeable).
Geocoding: https://developers.google.com/maps/documentation/javascript/examples/geocoding-simple
Once you get latitude and longitude, you can plot that location on map as a marker. Then add dragend event on marker which will allow you to get the marker drag event and eventually return you the new locations lat and lng. using this lat lng, you can get the address using reverse geocoding.
Reverse geocoding: https://developers.google.com/maps/documentation/javascript/examples/geocoding-reverse
For second requirement, As per my understanding you want to show the custom object's records which are some radius away from the current record?
For this, you will have to create geolocation field on custom object. Store latitude and longitude of custom object and then you can use geolocation query in apex where you can define radius and subject lat lng.
Geolocation soql: https://developer.salesforce.com/blogs/developer-relations/2012/10/winter-13-using-apex-and-soql-with-geolocation.html
I saw your this post and I am working on the same requirement. Can you please help me to complete this. If possible please share your skypeid or mail-id with me.
Thanks