Hello. Here I have a script to display google map with snazzy map styling copied from my old project which is a static location.
I want to replace the Lat & Lng dynamically with ACF map field. Not really familiar with the script. But would like to know if we could use the function get_field to get those values for these 2 lines?
center: new google.maps.LatLng(22.284687294722, 114.15541043858117),
position: { lat: 22.284687294722, lng: 114.15541043858117 },
With something like this?
$location = get_field(‘location’);
$lat = $location[‘lat’];
$lng $location[‘lng’];
Below is the part of the full code FYI. Thanks
<script type="text/javascript">
// When the window has finished loading create our google map below
google.maps.event.addDomListener(window, 'load', init);
function init() {
// Basic options for a simple Google Map
// For more options see: https://developers.google.com/maps/documentation/javascript/reference#MapOptions
var mapOptions = {
// How zoomed in you want the map to start at (always required)
zoom: 15,
center: new google.maps.LatLng(22.284687294722, 114.15541043858117),
disableDefaultUI: true,
// Let's also add a marker while we're at it
var image =
"https://example.com/Google-map-location.svg";
var beachMarker = new google.maps.Marker({
position: { lat: 22.284687294722, lng: 114.15541043858117 },
map,
icon: image,
});