使用CakePHP查询坐标数据库以返回Google地图的JSON [英] Using CakePHP to query a database of coordinates to return JSON for Google Map

查看:101
本文介绍了使用CakePHP查询坐标数据库以返回Google地图的JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下示例: http://dev.driz.co.uk/googlemap/ 代表我在CakePHP中构建的应用程序的映射功能(注意,此示例不使用Cake)。

I have the following example: http://dev.driz.co.uk/googlemap/ that represents the mapping functionality of an app I'm building in CakePHP (note this example isn't using Cake).

使用JSON,我填充Google地图和一些标记,并使用地理位置将地图定位在您的位置,本质上,你可以看到周围的帖子。因此,在现实生活的应用程序中,JSON文件将使用Cake从数据库动态构建。

Using JSON, I'm populating the Google Map with some markers and also using Geolocation to center the map on your location, essentially so you can see posts around you. So in the real life app that JSON file will be dynamically built using Cake from a database.

我想要做的是使用您的位置的坐标查询数据库以查找位于这些坐标的10英里半径范围内的帖子。和拉说10个帖子出...我然后想要使你可以拖动地图周围和加载更多的帖子,因为你扩展你的半径,如果这是有道理的。 问题是如何通过坐标/ 10英里半径回到CakePHP查询DB中的帖子!

What I want to do is using the coordinates of your location (the user) query the database to find posts that are say within a 10 mile radius of those coordinates. And pull say 10 posts out... I then want to make it so that you can drag the map around and load in more posts as you extend your radius if that makes sense. The problem is how to pass the coordinates/10 miles radius back to CakePHP to query the posts in the DB!

有任何例子这个?有人可以发布一些代码示例,可以帮助我开始构建这样的查询吗?我有一个查询从数据库中拉出10个帖子,但它不搜索基于坐标的帖子...我如何在一组坐标的集合10里程半径内做?

Are there any examples of this? And could someone post some code samples that could help to get me started building such a query? I have a query in place for pulling out 10 posts from the database, but it doesn't search for posts based on coordinates... How would I do that within a set 10 mile radius for a set of coordinates?

查询的示例是:

public function gMapTest() {

        $posts = $this->Post->find('all', array('limit'=>10,'conditions'=>array('Post.status'=>array(1,2)),'order'=>array('Post.datetime'=>'desc'),
        'contain'=>array('User'=>'Profile'))); 

        $this->set('posts',$posts);

        $this->set('_serialize', 'posts');
    }


推荐答案

模型:

$this->Post->Behaviors->attach('Tools.Geocoder');
$this->Post->setDistanceAsVirtualField($lat, $lng);
$options = array('order' => array('Post.distance' => 'ASC'), 'limit' => 10);
$posts = $this->Post->find('all', $options);

http://www.dereuromark.de/2012/06/12/geocoding-with-cakephp/

这篇关于使用CakePHP查询坐标数据库以返回Google地图的JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆