Example #1
0
        public static async Task <OpenCageContract> OpenMapReGeoAsync(double latitude, double longitude)
        {
            var OpenStreetUrl = "http://api.opencagedata.com/geocode/v1/json?q={0}+{1}&key={2}&language=zh-cn";
            var result        = await ApiRequestHelper.RequestWithFormattedUrlAsync(OpenStreetUrl, new string[] { latitude.ToString("0.######"), longitude.ToString("0.######"), Key.OpenCage });

            // json 生成类
            if (result == null)
            {
                return(null);
            }
            var omapRes = JsonHelper.FromJson <OpenCageContract>(result);

            return(omapRes);
        }
Example #2
0
        public static async Task <AmapContract> AmapReGeoAsync(double latitude, double longitude)
        {
            var requestUrl = "http://restapi.amap.com/v3/geocode/regeo?key={0}&location={1},{2}&radius=1000&extensions=all&batch=false&roadlevel=1";
            // 高德经纬度颠倒
            var result = await ApiRequestHelper.RequestWithFormattedUrlAsync(requestUrl, new string[] { Key.amap, longitude.ToString("0.######"), latitude.ToString("0.######") });

            // json 生成类
            if (result == null)
            {
                return(null);
            }
            var amapRes = JsonHelper.FromJson <AmapContract>(result);

            return(amapRes);
        }
Example #3
0
        public async static Task <HeWeather.Location> ReGeobyIpAsync()
        {
            var ipUrl  = "http://api.ip138.com/query/?token={0}";
            var result = await ApiRequestHelper.RequestWithFormattedUrlAsync(ipUrl, new string[] { Key.ip138 });

            if (result == null)
            {
                return(null);
            }
            var ipRes = JsonHelper.FromJson <IpContract>(result);
            var city  = await Request.RequestbyIpAsync(ipRes.ip);

            var fetchresult = HeWeatherModel.Generate(city, DataSource.HeWeather);

            return(fetchresult.Location);
        }
Example #4
0
        public async static Task <string> HeWeatherGeoLookup(string name)
        {
            var url    = "https://free-api.heweather.com/v5/search?key={0}&city={1}";
            var result = await ApiRequestHelper.RequestWithFormattedUrlAsync(url, new string[] { Key.ip138, name });

            if (result == null)
            {
                return(null);
            }
            var rees = JsonHelper.FromJson <HeWeatherCity>(result);

            if (!rees.HeWeather5.IsNullorEmpty())
            {
                return(rees.HeWeather5[0].basic.id);
            }
            else
            {
                return("");
            }
        }