简体   繁体   English

Adobe Air-IP定位

[英]Adobe Air - IP to location

Is there a way to get the broad position of a user based on the IP address? 有没有一种方法可以根据IP地址获得用户的广泛地位? (I'm building an Adobe Air desktop app for notebook users) (我正在为笔记本用户构建一个Adobe Air桌面应用程序)

Just tried out http://www.netimpact.com/ , like you were looking for it's broad position, it placed me 3.7 miles away from my actual location, seems relatively simple to use and can respond with delimited data that can be split using the split method or else can choose to get JSON encoded object data which can be easily read into an AS3 object in Flex using JSON.parse(). 只需尝试一下http://www.netimpact.com/ ,就像您在寻找它的宽幅位置一样,它使我与实际位置相距3.7英里,使用起来似乎比较简单,并且可以使用分隔的数据进行响应,可以使用split方法,否则可以选择获取JSON编码的对象数据,可以使用JSON.parse()轻松将其读取到Flex中的AS3对象中。 Be sure to read up the FAQ on their site to get a better understanding of how they retrieve the data and what the accuracy is generally like, they allow 1000 requests per developer per day if you need more they have pricing starting at 20 bucks a month. 请务必阅读他们网站上的常见问题解答,以更好地了解他们如何检索数据以及准确度如何,如果您需要更多的信息,他们每天可以为每个开发人员提供1000个请求,而起价为每月20美元。

NOTE: Netimpact has shut down and they migrated users to their new provider, KickFire . 注意:Netimpact已关闭,他们将用户迁移到了新的提供者KickFire They've also broadened their offering to include not only IP2GEO, but also IP2Company, & Domain2IP. 他们还扩大了产品范围,不仅包括IP2GEO,还包括IP2Company和Domain2IP。

EDIT: 编辑:

A bit more information on exploring this further and some sample code. 有关进一步研究和一些示例代码的更多信息。 So the only problem I'm seeing with my solution is getting the WAN IP address, I think you'll need to use some sort of server side script to bounce back the users external IP in order to make this work entirely. 因此,我在解决方案中遇到的唯一问题是获取WAN IP地址,我认为您需要使用某种服务器端脚本来反弹用户的外部IP,以使其完全正常工作。 I attempted using the NetworkInfo but this will always be reporting based on LAN IP addresses which won't work for the geoip look-up. 我尝试使用NetworkInfo,但这将始终基于基于LAN IP地址的报告,不适用于geoip查找。 So this leads me to using PHP or some other server side script for obtaining the IP. 因此,这导致我使用PHP或其他服务器端脚本来获取IP。 Further discussion on getting the IP using PHP here: http://www.phpbuilder.com/board/showthread.php?t=10327697 有关使用PHP获取IP的更多讨论, 请参见http ://www.phpbuilder.com/board/showthread.php?t= 10327697

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                       xmlns:s="library://ns.adobe.com/flex/spark" 
                       xmlns:mx="library://ns.adobe.com/flex/mx"
                       creationComplete="windowedapplication1_creationCompleteHandler(event)">

    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;
            import mx.rpc.events.ResultEvent;
            import mx.rpc.http.HTTPService;

            private const MY_API_KEY:String = "PUT YOUR OWN KEY HERE";

            [Bindable]
            private var ipLookupResult:Object;

            protected function button1_clickHandler(event:MouseEvent):void
            {
                var httpService:HTTPService = new HTTPService();
                httpService.url = "http://api.geoio.com/q.php?key="+MY_API_KEY+"&qt=geoip&d=json&q=PUT_YOUR_IP_HERE";
                httpService.addEventListener(ResultEvent.RESULT, lookupResultHandler);
                httpService.send();
            }
            private function lookupResultHandler(event:ResultEvent):void
            {
                ipLookupResult = JSON.parse(event.result as String);
            }

            protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
            {
                for each(var ni:NetworkInterface in NetworkInfo.networkInfo.findInterfaces())
                {
                    var addresses:Vector.<InterfaceAddress> = ni.addresses;
                    var userIp:String = addresses[0].address;
                    trace(userIp);
                }
            }

        ]]>
    </fx:Script>

    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:layout>
        <s:VerticalLayout/>
    </s:layout>
    <s:Button click="button1_clickHandler(event)" label="Look me up"/>
    <s:Form>
        <s:FormItem label="City">
            <s:Label text="{ipLookupResult[0][0]}"/>
        </s:FormItem>
        <s:FormItem label="State">
            <s:Label text="{ipLookupResult[0][1]}"/>
        </s:FormItem>
        <s:FormItem label="Country">
            <s:Label text="{ipLookupResult[0][2]}"/>
        </s:FormItem>
        <s:FormItem label="ISP">
            <s:Label text="{ipLookupResult[0][3]}"/>
        </s:FormItem>
        <s:FormItem label="Latitude">
            <s:Label text="{ipLookupResult[0][4]}"/>
        </s:FormItem>
        <s:FormItem label="Longitude">
            <s:Label text="{ipLookupResult[0][5]}"/>
        </s:FormItem>
        <s:FormItem label="Country Code">
            <s:Label text="{ipLookupResult[0][6]}"/>
        </s:FormItem>
    </s:Form>
</s:WindowedApplication>

If you don't have access to write your own server side scripts you can also look to external services to obtain the information, I believe whatismyip.com offers this but not sure about licensing/cost and I know they specifically don't want you to use the main page to scrape out the IP (there's undoubtedly some free version of this service available if they charge). 如果您无权编写自己的服务器端脚本,也可以借助外部服务来获取信息,我相信whatismyip.com会提供此信息,但不确定许可/成本,我知道他们特别希望您使用主页抓取IP(无疑,如果收费的话,可以使用此服务的一些免费版本)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM