如何解决Google集群地图,带有ACF的位置数组
我使用的是位于此处的标准群集Google地图:https://developers.google.com/maps/documentation/javascript/marker-clustering
在示例中,我的工作正常。 我正在尝试将Acf连接到我的cpt上很长时间,然后将其放置在const数组中。
代替使用标准:
const locations = [
{ lat: -33.718234,lng: 150.363181 },{ lat: -33.727111,lng: 150.371124 },{ lat: -33.848588,lng: 151.209834 },{ lat: -33.851702,lng: 151.216968 },{ lat: -34.671264,lng: 150.863657 },{ lat: -35.304724,lng: 148.662905 },{ lat: -36.817685,lng: 175.699196 },{ lat: -36.828611,lng: 175.790222 },{ lat: -37.75,lng: 145.116667 },{ lat: -37.759859,lng: 145.128708 },{ lat: -37.765015,lng: 145.133858 },{ lat: -37.770104,lng: 145.143299 },{ lat: -37.7737,lng: 145.145187 },{ lat: -37.774785,lng: 145.137978 },{ lat: -37.819616,lng: 144.968119 },{ lat: -38.330766,lng: 144.695692 },{ lat: -39.927193,lng: 175.053218 },{ lat: -41.330162,lng: 174.865694 },{ lat: -42.734358,lng: 147.439506 },lng: 147.501315 },{ lat: -42.735258,lng: 147.438 },{ lat: -43.999792,lng: 170.463352 },];
我已经设置好了
const locations = [
<?php
$args = array(
'post_type' => 'stockists','posts_per_page' => -1
);
$places = new WP_Query($args);
if($places->have_posts()){
while($places->have_posts()) {
the_post();?>
{lat:<?php echo get_field('lat') ?>,lng:<?php echo get_field('long') ?>},<?php }} ?>
];
但是我遇到这些错误:
通知:未定义的偏移量:15 in /home/sites/7b/d/de4743ded0/public_html/typhoon/wp-includes/class-wp-query.php 在 3284
['',
我尝试使用条件acf仅显示填充的帖子,但仍然没有运气。当前只有一篇文章是冗长而滞后的。
我需要在acf中包含长号和纬度,因为用户将需要通过CSV导入,因此我无法手动添加它们。
真的卡住了,任何帮助将不胜感激!
解决方法
我的帖子查询略有结束,我在acf周围包裹了一个条件。
const locations = [
<?php
$args = array(
'post_type' => 'stockists','posts_per_page' => -1
);
$places = new WP_Query($args);
if($places->have_posts()){
while($places->have_posts()) {
$places->the_post(); ?>
<?php if (get_field('lat')) : ?>
{lat:<?php echo get_field('lat') ?>,lng:<?php echo get_field('long') ?>},<?php endif; ?>
<?php } ?>
<?php wp_reset_postdata(); ?>
<?php } ?>
];
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。