0

I'm just looking for some help for the best way to do this and if there's any recommendations on a better way. So I have a Google map on one of the web pages, I need to add multiple marks to show store locations. I am using ACF to store the data of the stores in a repeater and am using a custom post type to call the data from ACF.

Is there a better way to do this or any further recommendations?

1 Answers1

0

Maybe this can help you in the right direction. I have a website on which I use a custom field where you can enter the desired address of a location ($address) to find lat/long for the given address.

$address       = get_field( 'adress' );

// Convert adress to lat/long
$findaddress  = urlencode($address);
$requesturl   = "http://maps.googleapis.com/maps/api/geocode/xml?address=".$address."&sensor=true";
$xml           = simplexml_load_file($requesturl) or die("not found");

$status = $xml->status;

    if ($status=="OK") {
        $latitude   = $xml->result->geometry->location->lat;
        $longitude  = $xml->result->geometry->location->lng;
    }

The given lat/long can than be used to add a location, marker, center etc:

// Location of the given address
var location = new google.maps.LatLng(<?php print $latitude ?>,<?php print $longitude; ?>);

// Map
var map = new google.maps.Map(document.getElementById('google-maps'), {
    zoom:               18,
    disableDefaultUI:   true,
    scrollwheel:        false,
    styles:             styles,
    center:             location,
    mapTypeId:          google.maps.MapTypeId.ROADMAP,
});

// Marker
var marker = new google.maps.Marker({
    map:                map,
    position:           location,
});