尊龙凯时人生就是搏

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

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

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

´úÂëʾÀý£º

// »ñÈ¡Ä¿½ñÇëÇóµÄ IP µØµã
$client_ip = request()->ip();
// ʹÓðٶȵØͼ API »ñÈ¡µØÓßλÖÃÐÅÏ¢
$url = "http://api.map.m.zuhaoqu.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Ôõô»ñÈ¡Ðû²¼Õߵصã±ê×¢µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是搏

18523999891

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

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

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