ÔõÑùʹÓÃThinkPHP6¾ÙÐеØÀí¶¨Î»²Ù×÷£¿
Ëæ×ÅÒƶ¯»¥ÁªÍøµÄ¿ìËÙÉú³¤£¬µØÀí¶¨Î»¹¦Ð§ÒѾ³ÉΪÁËÐí¶àÓ¦ÓóÌÐòÖбز»¿ÉÉٵĹ¦Ð§£¬ÈÃÓû§Äܹ»Ô½·¢Àû±ãµØ»ñÈ¡ÖܱßÐÅÏ¢£¬Ò²ÎªÉ̼ÒÌṩÁ˱ã½ÝµÄ½»»¥·½·¨¡£¶øÔÚÓ¦ÓÃÖÐʵÏÖµØÀí¶¨Î»¹¦Ð§£¬thinkphp6¿ò¼ÜÒ²ÌṩÁ˽ÏΪ±ã½ÝµÄ½â¾ö¼Æ»®¡£
±¾ÎĽ«ÏÈÈÝʹÓÃThinkPHP6¾ÙÐеØÀí¶¨Î»²Ù×÷µÄÏêϸҪÁì¼°°ì·¨¡£
Ò»¡¢×°ÖÃÀ©Õ¹
ÔÚʹÓÃÇ°£¬ÐèҪװÖÃthinkphp¹Ù·½ÌṩµÄthink-geoÀ©Õ¹£¬Ê¹ÓÃcomposer×°Öü´¿É¡£
composer require topthink/think-geo
µÇ¼ºó¸´ÖÆ
¶þ¡¢ÉèÖÃ
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
ÔÚÉèÖÃÎļþconfig/app.phpÖÐÉèÖÃÀ©Õ¹µÄprovidersÏÌí¼Ó hinkGeoServiceProviderЧÀÍÌṩÕß¼´¿É¡£
'providers' => [ // ¸ü¶àµÄЧÀÍÌṩÕß hinkGeoServiceProvider::class ],
µÇ¼ºó¸´ÖÆ
Èý¡¢Ê¹ÓÃ
»ñÈ¡µØÀí±àÂë
µØÀí±àÂë¼´½«ÈËÀà¿É¶ÁµÄµØµãת»»³ÉÅÌËã»ú¿É¶ÁµÄ¾Î³¶ÈÊýÖµ£¬Ê¹µÃÎÒÃÇÄܹ»Í¨¹ý¾Î³¶ÈÀ´Ïêϸ¶¨Î»ËùÔÚ¡£ÔÚThinkPHP6ÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃGeoÀàÀ´¿ìËÙ¾ÙÐеØÀí±àÂë²Ù×÷¡£
use thinkGeo; $address = '¹ã¶«Ê¡¹ãÖÝÊÐÌìºÓÇø»ª¾°Â·61ºÅ»ª¾°ÐÂÌìµØ'; $result = Geo::geocode($address); dump($result);
µÇ¼ºó¸´ÖÆ
´úÂëÖÐ$addressΪÐèÒª¾ÙÐеØÀí±àÂëµÄµØµã£¬Geo::geocode()º¯Êý½«·µ»ØÒ»¸öGeoResult¹¤¾ß£¬¸Ã¹¤¾ß°üÀ¨Á˸õصãµÄµØÀí±àÂëÐÅÏ¢£¬°üÀ¨¾Î³¶È¡¢ËùÔÚ¹ú¼Ò/Ê¡·Ý/¶¼»á/ÇøÓòµÈÐÅÏ¢¡£
»ñÈ¡ÄæµØÀí±àÂë
ÄæµØÀí±àÂë¼´½«ÅÌËã»ú¿É¶ÁµÄ¾Î³¶ÈÊýֵת»»³ÉÈËÀà¿É¶ÁµÄµØµã¡£ÔÚThinkPHP6ÖУ¬ÎÒÃÇÖ»ÐèҪŲÓÃGeoÀàµÄreverseGeocode()º¯Êý¼´¿É»ñÈ¡ÄæµØÀí±àÂëÐÅÏ¢¡£
use thinkGeo; $lng = 113.324520; // ¾¶È $lat = 23.102290; // γ¶È $result = Geo::reverseGeocode($lng, $lat); dump($result);
µÇ¼ºó¸´ÖÆ
´úÂëÖÐ$lngºÍ$latΪÐèÒª¾ÙÐÐÄæµØÀí±àÂëµÄ¾Î³¶ÈÊýÖµ£¬Geo::reverseGeocode()º¯Êý½«·µ»ØÒ»¸öGeoResult¹¤¾ß£¬¸Ã¹¤¾ß°üÀ¨Á˸þγ¶ÈËùÔڵصãµÄµØÀí±àÂëÐÅÏ¢¡£
ËÄ¡¢×ܽá
ÒÔÉϾÍÊÇʹÓÃThinkPHP6¾ÙÐеØÀí¶¨Î»²Ù×÷µÄÏêϸҪÁì¼°°ì·¨¡£Í¨¹ýÓ¦ÓøÃÀ©Õ¹£¬ÎÒÃÇ¿ÉÒÔÇáËÉʵÏÖÓ¦ÓÃÖеĵØÀí¶¨Î»¹¦Ð§£¬ÎªÓû§ÌṩԽ·¢±ãµ±µÄЧÀÍ¡£
ÒÔÉϾÍÊÇÔõÑùʹÓÃThinkPHP6¾ÙÐеØÀí¶¨Î»²Ù×÷£¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡