hypejunction/hypegeo

用于构建Elgg地理感知插件的工具

安装: 161

依赖: 0

建议者: 0

安全性: 0

星标: 5

关注者: 4

分支: 4

开放问题: 1

类型:elgg-plugin

1.0.2 2014-04-23 11:13 UTC

This package is auto-updated.

Last update: 2024-08-29 03:17:47 UTC


README

旨在简化位置感知开发的多种工具

我的手机账单要到期了!

依赖项

  • 如果从github下载,请运行 composer install 安装composer依赖项

MySQL空间扩展

  • 插件通过添加一个具有几何功能的 prefix_entity_geometry 表,并使用唯一的 entity_guid 键来优化地理坐标的存储。每当 location 元数据更新时,元数据值将被地理编码,相应的坐标将存储在几何功能的表中。这允许减少对按距离排序实体到给定地理位置或选择特定范围内实体的开销。

  • 当您首次激活插件时,脚本将遍历所有带有 geo:latgeo:long 元数据的实体,并填充几何表。

  • 默认的Elgg元数据存储和更新工作流程保持不变,因此可以在任何时间安全地禁用插件而不会丢失任何数据。

过滤

插件提供API以通过距离特定地理位置来获取实体,并提供方便的函数将必要的子句添加到您的 elgg_get_entities_* 选项数组中。

有关示例实现,请参阅搜索钩子。

基于位置搜索

插件实现了基于位置搜索类型,在给定半径内的实体将在搜索结果中显示,并且如果是一个可地理编码的位置,则按距离搜索查询的顺序排序。

地理编码

  • 地理编码通过使用William Durand的PHP Geocoder库通过多个提供商进行 https://github.com/geocoder-php/Geocoder

  • 在插件设置中可以找到对个别提供商的配置。

  • 地理编码的地址/位置将在 prefix_geocode_cache 中缓存。

地理计算

视图

插件添加了几个视图,这些视图有助于标准化位置感知UI。

表单视图

  • forms/geo/postal_address - 标准邮政地址表单(提交一个配置名称的数组)操作将接收到以下键的数组:street_addressextended_addresslocalityregionpostal_codecountry_code

输入视图

  • input/geo/location - 位置输入带有自动完成(来自现有的位置元数据)需要elgg_tokeninput输入进行自动完成 https://github.com/hypeJunction/elgg_tokeninput

  • input/geo/country - 国家选择器(将ISO代码作为选项值传递)

输出视图

  • output/geo/location
  • output/geo/country

示例

以下示例将在当前用户200公里范围内显示用户列表,并按距离排序。请注意,此示例假定您已正确地理编码了当前登录用户的详细信息。

$current_user = elgg_get_logged_in_user_entity();
$lat = $current_user->getLatitude();
$long = $current_user->getLongitude();

$radius = 200 * 1000; // 200km in meters

$params = array(
	'types' => 'user',
	'full_view' => false,
	// other getter and lister options
);

$params = \hypeJunction\Geo\add_distance_constraint_clauses($params, $lat, $long, $radius);
$params = \hypeJunction\Geo\add_order_by_proximity_clauses($params, $lat, $long);

echo elgg_list_entities($params);

以下示例将在默认顺序(time_created)中显示距离默认地址500米范围内的博客和书签列表。

$location = "Potsdamerstr. 56, Berlin";

$coords = elgg_geocode_location($location);
$lat = $coords['latitude'];
$long = $coords['longitude'];

$params = array(
	'types' => 'object',
	'subtypes' => array('blog','bookmarks'),
	'full_view' => false,
	// other getter and lister options
);

$params = \hypeJunction\Geo\add_distance_constraint_clauses($params, $lat, $long, 500);

echo elgg_list_entities($params);

以下示例将显示距离另一个实体最近的20个精选群组列表。

$guid = get_input('guid');
$entity = get_entity($guid);

if (elgg_instanceof($entity)) {
	$lat = $entity->getLatitude();
	$long = $entity->getLongitude();
}

if ($lat && $long) {
	$options = array(
		'types' => 'group',
		'metadata_name_value_pairs' => array(
			'name' => 'featured_group', 'value' => 'yes'
		),
		'limit' => 20
	);

	$entities = \hypeJunction\Geo\get_entities_by_proximity($options, $lat, $long, 'elgg_get_entities_from_metadata');
	echo elgg_view_entity_list($entities, array(
		'pagination' => false,
		'full_view' => false
	));
}

屏幕截图

alt text alt text