Post title and url not showing on google map marker [SOLVED]

I have managed to show multiple markers but I can’t show the post title and to make the same post title as URL to go to a single page.

Here is the code in functions.php

$args = array(‘post_type’ => ‘post’,array(
‘meta_query’ => array(
‘relation’ => ‘AND’,
array(
‘key’ => ‘lng’,
),
array(
‘key’ => ‘lat’,
)
)
));
$loop = new WP_Query($args);

while ( $loop->have_posts() ) : $loop->the_post();

$title = get_the_title();
$post_category=get_the_category();
$post_category_name=$post_category[0]->cat_name;
$permalink=get_the_permalink();

$lng = get_post_meta( get_the_ID(), ‘lng’, TRUE );
$lat = get_post_meta( get_the_ID(), ‘lat’, TRUE );

$lnglat=$lng.”,”.$lat;

$arrlatlng[]=array(
“lnglat”=>$lnglat,
“post_title”=>$title,
‘post_category’=>$post_category_name,
‘post_url’=>$permalink);
$longitude[]=array(‘lng’=>$lng);
$latitude[]=array(‘lat’=>$lat);
endwhile;
$passedValues = array( ‘retrieve_data’ => $retrieve_data,
‘var1’ => $arrlatlng,’lng’=>$longitude,’lat’=>$latitude
);
wp_localize_script( ‘spektrum_gmap.js’, ‘passed_object’, $passedValues );

function myMap() {

var myCenter = new google.maps.LatLng(44.794426, 20.451849);
var mapProp = {center:myCenter, zoom:15, scrollwheel:false, draggable:true,
mapTypeId:google.maps.MapTypeId.ROADMAP};
var map = new google.maps.Map(document.getElementById(“googleMap”),mapProp);
var myJsarray = passed_object.retrieve_data;

var latitute = ” ;
var longitute = ”;

var lng = passed_object.lng;
var lat = passed_object.lat;
var content= passed_object.var1;
var post_title=content.post_title

for (var i=0; i<lng.length; i++) {
var marker=new google.maps.Marker({
position: new google.maps.LatLng( lat[i].lat , lng[i].lng),
map: map,
title: content[i].post_title,
url:content[i].post_url,
content:content[i].post_title,
label: {
text: content[i].post_title,
color: “#000”,
fontSize: “16px”,
fontWeight: “bold”,
}
});
}

google.maps.event.addListener(marker, ‘click’, function() {
window.location.href = this.url;
});

marker.setMap(map,content);

}

Read more here:: Post title and url not showing on google map marker [SOLVED]

Leave a Reply

Your email address will not be published. Required fields are marked *