×ðÁú¿­Ê±

ThinkPHPÔõô»ñÈ¡Ðû²¼Õߵصã±ê×¢

Ò»¡¢Ê¹Óà IP µØµã»ñÈ¡Ðû²¼Õߵصã±ê×¢

ÔÚ»ñÈ¡Ðû²¼Õߵصã±êעʱ£¬¿ÉÒÔʹÓÃÆä IP µØµã¾ÙÐж¨Î»¡£ÔÚ ThinkPHP ÖУ¬¿ÉÒÔͨ¹ý getRequest() ÒªÁì»ñÈ¡Ä¿½ñÇëÇóµÄ IP µØµã£¬ÔÙʹÓõÚÈý·½µØÀíλÖÃЧÀÍ£¨Èç°Ù¶ÈµØͼ API£©¾ÙÐÐÆÊÎö£¬»ñÈ¡¶ÔÓ¦µÄµØÀíλÖÃÐÅÏ¢¡£

´úÂëʾÀý£º

// »ñÈ¡Ä¿½ñÇëÇóµÄ IP µØµã
$client_ip = request()->ip();
// ʹÓðٶȵØͼ API »ñÈ¡µØÀíλÖÃÐÅÏ¢
$url = "http://api.map.m.blockadm.com/location/ip?ak=ÄúµÄÃÜÔ¿&ip=$client_ip&coor=bd09ll";
$result = file_get_contents($url);
$location = json_decode($result, true);
$address = $location['content']['address'];

µÇ¼ºó¸´ÖÆ

ÆäÖУ¬$client_ip ±äÁ¿´æ´¢Ä¿½ñÇëÇóµÄ IP µØµã£¬$url ±äÁ¿´æ´¢Å²ÓðٶȵØͼ API µÄ URL µØµã£¬$result ±äÁ¿´æ´¢ÆÊÎöЧ¹û£¬$location ±äÁ¿ÎªÆÊÎöЧ¹ûµÄÊý×éÐÎʽ£¬$address ±äÁ¿´æ´¢×îÖÕ»ñÈ¡µÄµØµã±ê×¢ÐÅÏ¢¡£

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡± £»

¶þ¡¢Ê¹ÓÃä¯ÀÀÆ÷¶¨Î»»ñÈ¡Ðû²¼Õߵصã±ê×¢

³ýÁËʹÓà IP µØµã¶¨Î»»ñȡλÖñê¼Ç£¬»¹¿ÉÒÔʹÓÃä¯ÀÀÆ÷¶¨Î»À´»ñȡλÖñê¼Ç¡£ÔÚ ThinkPHP ÖУ¬¿ÉÒÔʹÓà JavaScript »ñÈ¡ä¯ÀÀÆ÷¶¨Î»£¬ÔÙʹÓõÚÈý·½µØÀíλÖÃЧÀÍ£¨ÈçÌÚѶµØͼ API£©¾ÙÐÐÆÊÎö£¬»ñÈ¡¶ÔÓ¦µÄµØµã±ê×¢ÐÅÏ¢¡£

´úÂëʾÀý£º

// Ò³ÃæÖÐÒýÈë JavaScript ¶¨Î»´úÂë
navigator.geolocation.getCurrentPosition(function(position) {
    // »ñÈ¡ä¯ÀÀÆ÷¶¨Î»µÄ¾­Î³¶È
    var lat = position.coords.latitude;
    var lng = position.coords.longitude;
    // ʹÓÃÌÚѶµØͼ API »ñÈ¡µØÀíλÖÃÐÅÏ¢
    var url = "https://apis.map.qq.com/ws/geocoder/v1/?location=" + lat + "," + lng + "&key=ÄúµÄÃÜÔ¿&get_poi=0";
    $.ajax({
        url: url,
        dataType: "jsonp",
        success: function(result) {
            // ÆÊÎöЧ¹û£¬»ñÈ¡µØµã±ê×¢ÐÅÏ¢
            var address = result.result.formatted_addresses.recommend;
        }
    })
});

µÇ¼ºó¸´ÖÆ

ÆäÖУ¬navigator.geolocation.getCurrentPosition() ÒªÁì»ñÈ¡ä¯ÀÀÆ÷¶¨Î»£¬lat ºÍ lng ±äÁ¿´æ´¢»ñÈ¡µÄ¾­Î³¶ÈÐÅÏ¢£¬url ±äÁ¿´æ´¢Å²ÓÃÌÚѶµØͼ API µÄ URL µØµã£¬success ²ÎÊýÄڵĴúÂë»ñÈ¡ÆÊÎöЧ¹û£¬²¢»ñÈ¡×îÖյĵصã±ê×¢ÐÅÏ¢¡£

ÒÔÉϾÍÊÇThinkPHPÔõô»ñÈ¡Ðû²¼Õߵصã±ê×¢µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±ÊµÊ±ÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±

13452372176

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
¡¾ÍøÕ¾µØͼ¡¿¡¾sitemap¡¿