<i id='5xnxW'><tr id='5xnxW'><dt id='5xnxW'><q id='5xnxW'><span id='5xnxW'><b id='5xnxW'><form id='5xnxW'><ins id='5xnxW'></ins><ul id='5xnxW'></ul><sub id='5xnxW'></sub></form><legend id='5xnxW'></legend><bdo id='5xnxW'><pre id='5xnxW'><center id='5xnxW'></center></pre></bdo></b><th id='5xnxW'></th></span></q></dt></tr></i><div id='5xnxW'><tfoot id='5xnxW'></tfoot><dl id='5xnxW'><fieldset id='5xnxW'></fieldset></dl></div>
    1. <small id='5xnxW'></small><noframes id='5xnxW'>

        <bdo id='5xnxW'></bdo><ul id='5xnxW'></ul>
    2. <legend id='5xnxW'><style id='5xnxW'><dir id='5xnxW'><q id='5xnxW'></q></dir></style></legend>

        <tfoot id='5xnxW'></tfoot>
      1. 将用户的位置存储在数据库中并为他找到最近的用户

        Storing user#39;s location in DB and find the nearest users for him(将用户的位置存储在数据库中并为他找到最近的用户)

        <small id='VL3DK'></small><noframes id='VL3DK'>

            <i id='VL3DK'><tr id='VL3DK'><dt id='VL3DK'><q id='VL3DK'><span id='VL3DK'><b id='VL3DK'><form id='VL3DK'><ins id='VL3DK'></ins><ul id='VL3DK'></ul><sub id='VL3DK'></sub></form><legend id='VL3DK'></legend><bdo id='VL3DK'><pre id='VL3DK'><center id='VL3DK'></center></pre></bdo></b><th id='VL3DK'></th></span></q></dt></tr></i><div id='VL3DK'><tfoot id='VL3DK'></tfoot><dl id='VL3DK'><fieldset id='VL3DK'></fieldset></dl></div>
              <tbody id='VL3DK'></tbody>

              1. <legend id='VL3DK'><style id='VL3DK'><dir id='VL3DK'><q id='VL3DK'></q></dir></style></legend>
                • <bdo id='VL3DK'></bdo><ul id='VL3DK'></ul>
                • <tfoot id='VL3DK'></tfoot>
                  本文介绍了将用户的位置存储在数据库中并为他找到最近的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试实现一个用户系统,系统要求之一是找到您附近的其他用户.

                  位置将按国家/地区过滤,而不是按城市过滤,因此用户可以找到来自同一国家但来自不同城市的其他用户.

                  问题是如何计算城市之间的距离?它不一定要 100% 准确,但它必须优先考虑更接近的用户.

                  Google 地理位置 API 会满足这些要求吗?有哪些替代方案?

                  知道如何在不进行大量计算的情况下实现它吗?

                  我想问用户国家和城市只是为了写在他的个人资料中,并从它的 IP 中获取它的地理位置,或者导入一个包含所有城市及其地理位置的数据库.

                  请指导我.

                  解决方案

                  你可以使用 Haversine 公式在数据库中搜索最近的用户.

                  $stmt = $dbh->prepare("SELECT name, lat, lng, ( 3959 * acos( cos( radians(?) ) * cos( radians( lat ) ) * cos( radians( lng) - 弧度(?) ) + sin( 弧度(?) ) * sin( 弧度( lat ) ) ) AS 距离从mytable HAVING 距离< ? ORDER BY distance LIMIT 0 , 20");//赋值参数$stmt->bindParam(1,$center_lat);//用户的纬度坐标$stmt->bindParam(2,$center_lng);//用户lng坐标$stmt->bindParam(3,$center_lat);$stmt->bindParam(4,$radius);//以英里为单位的半径

                  可以在 地名上找到城市数据库/p>

                  I am trying to implement a user system, one of the system requirements is find other users that are near you.

                  Location will be filtered by countries but not by cities, so users can get other users from the same country but from different city.

                  The question is how to calculate distances between cities? It doesn't have to be 100% accurate but it have to give some priority for closer users.

                  Will Google Geo location API will satisfy those requirements? What are the alternatives?

                  Any idea how to implement it without a very heavy calculation?

                  I thought of asking the user it's country and city just for writing in his profile, and get it's geo location from it's IP OR import a database which contains all cities and their geo location.

                  Please direct me.

                  解决方案

                  You can use the Haversine formula to search for nearest user in a database.

                  $stmt = $dbh->prepare("SELECT  name, lat, lng, ( 3959 * acos( cos( radians(?) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(?) ) + sin( radians(?) ) * sin( radians( lat ) ) ) ) AS distance FROM mytable HAVING distance < ? ORDER BY distance LIMIT 0 , 20");
                      // Assign parameters
                      $stmt->bindParam(1,$center_lat);//lat coordinate of user
                      $stmt->bindParam(2,$center_lng);//lng coordinate of user
                      $stmt->bindParam(3,$center_lat);
                      $stmt->bindParam(4,$radius);//Radius in miles 
                  

                  A database of cities can be found at Geonames

                  这篇关于将用户的位置存储在数据库中并为他找到最近的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                    <legend id='bgEJC'><style id='bgEJC'><dir id='bgEJC'><q id='bgEJC'></q></dir></style></legend>

                        <tbody id='bgEJC'></tbody>

                        <tfoot id='bgEJC'></tfoot>
                        • <bdo id='bgEJC'></bdo><ul id='bgEJC'></ul>

                          <small id='bgEJC'></small><noframes id='bgEJC'>

                          • <i id='bgEJC'><tr id='bgEJC'><dt id='bgEJC'><q id='bgEJC'><span id='bgEJC'><b id='bgEJC'><form id='bgEJC'><ins id='bgEJC'></ins><ul id='bgEJC'></ul><sub id='bgEJC'></sub></form><legend id='bgEJC'></legend><bdo id='bgEJC'><pre id='bgEJC'><center id='bgEJC'></center></pre></bdo></b><th id='bgEJC'></th></span></q></dt></tr></i><div id='bgEJC'><tfoot id='bgEJC'></tfoot><dl id='bgEJC'><fieldset id='bgEJC'></fieldset></dl></div>