ÔõÑùʹÓÃ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¾ÙÐеØÓ߶¨Î»²Ù×÷£¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡