在这里有一个很好的例子,可以在商店定位器中使用Google地图:http://code.google.com/apis/maps/articles/phpsqlsearch_v3.html
该示例使用一个包含3列的简单表 - 地址,纬度,经度。
我正在尝试使用自定义帖子类型为每个新位置将其整合到wordpress中,并且我已成功地将地址,纬度和经度值与每个新自定义帖子一起保存为元数据。
我正在努力做的是将此数据/查询转换为XML,与谷歌示例提供的方式相同。
将所有数据保存在WordPress自定义帖子中而不创建一个完整的单独表来处理它会很好。
以下是标准示例查询:
// Search the rows in the markers table
$query = sprintf("SELECT address, name, lat, lng, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20",
mysql_real_escape_string($center_lat),
mysql_real_escape_string($center_lng),
mysql_real_escape_string($center_lat),
mysql_real_escape_string($radius));
$result = mysql_query($query);
你如何模仿这个在wordpress CPT元数据中工作?
答案 0 :(得分:2)
我已经想到了 - 这是SQL查询:
SELECT wp_posts.post_title as name,
address.meta_value as address,
latitude.meta_value as lat,
longitude.meta_value as lng,
telephone.meta_value as telephone,
( 3959 * acos(
cos( radians( '%s' ) ) *
cos( radians( CONVERT( latitude.meta_value, DECIMAL( 10, 6 ) ) ) ) *
cos( radians( CONVERT( longitude.meta_value, DECIMAL( 10, 6 ) ) ) - radians( '%s' ) ) +
sin( radians( '%s' ) ) * sin( radians( CONVERT( latitude.meta_value, DECIMAL( 10, 6 ) ) ) )
) ) AS distance
FROM wp_posts
LEFT JOIN wp_postmeta AS address ON(
wp_posts.ID = address.post_id
AND address.meta_key = '_dealer_address'
)
LEFT JOIN wp_postmeta AS latitude ON(
wp_posts.ID = latitude.post_id
AND latitude.meta_key = '_dealer_latitude'
)
LEFT JOIN wp_postmeta AS longitude ON(
wp_posts.ID = longitude.post_id
AND longitude.meta_key = '_dealer_longitude'
)
LEFT JOIN wp_postmeta AS telephone ON(
wp_posts.ID = telephone.post_id
AND telephone.meta_key = '_dealer_telephone'
)
WHERE wp_posts.post_type = 'dealers' HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20