Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Google Maps WordPress

  • SOLVED

Hi Guys,

**Edited / fixed it myself through passing variables to the address (thanks for the pointer/reminder this was missing!)**

Answers (4)

2016-12-15

Arnav Joy answers:

Can you show me your site ?


changeinthesub comments:

It's on a local dev site but the code definitely needs a clean up (can't touch or access the live one). What it's doing is pulling the google maps ACF field from the single custom posts onto one page with a map with markers of the places near you. Above the map is a postcode/suburb search field and below the map shows the places nearby with their name, distance from you and other relevant information it pulls from their post.

I'm happy to have the code rewritten (and pay extra for that) but this is an urgent item. I can probably get you backend access asap to see the structure more?

2016-12-15

Kyle answers:

Do you have a live example somewhere?


Kyle comments:

You are passing the marker function a seemingly empty variable

setMarkers(map, address);

Which you then are using as the locations variable. That address variable needs to contain an area of all your location marker data.


changeinthesub comments:

It's on a dev site so no but you are right - i thought the issue was here too at my first pass. The only error I get relates to this (should've stated that in the Q). - ReferenceError: address is not defined.

Got a pointer on a quick fix?


changeinthesub comments:

Fixed this myself by passing and array of variables - thanks!

2016-12-15

Reigel Gallarde answers:

I'm reading your code and it's kind of a mess...

Do you have a link to look at? I'm also willing to work on this...

2016-12-15

Luis Abarca answers:

You have this on your code
image = '<?php echo get_template_directory_uri().'/assets/images/map.png'; ?>';

It should be

image = '<?php echo get_template_directory_uri() ?>/assets/images/map.png';


Luis Abarca comments:

Sorry, i added // to my code, try to replace your function with this one.

function setMarkers(map, locations)
{
for (var i = 0; i < locations.length; i++) {
if (i == 0) {
image = "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";
} else {
image = '<?php echo get_template_directory_uri().'/assets/images/map.png'; ?>';
}

var address = locations[i];
var myLatLng = new google.maps.LatLng(address[1], address[2]);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: image,
title: 'Test',
num: i
});

if (i != 0) {
addInfoWindow(marker, address[0]);
}

}
}


Luis Abarca comments:


function setMarkers(map, locations)
{
for (var i = 0; i < locations.length; i++) {
if (i == 0) {
image = "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";
} else {
image = '<?php echo get_template_directory_uri() ?>/assets/images/map.png';
}

var address = locations[i];
var myLatLng = new google.maps.LatLng(address[1], address[2]);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: image,
title: 'Test',
num: i
});

if (i != 0) {
addInfoWindow(marker, address[0]);
}

}
}


changeinthesub comments:

Nice pick up on the image :) Changed that and no luck. Can't see anything different in the rest of this function but replaced just in case with no luck either. It's a whole lot of code I know!