コード例 #1
0
        public static GeocoderResult gpsToAddress(string body)
        {
            GeocoderResult geocoder   = new GeocoderResult();
            JsonObject     jsonObject = JsonObject.Parse(body);
            int            status     = (int)jsonObject.GetNamedNumber("status");

            if (status == 0)
            {
                JsonObject result = jsonObject.GetNamedObject("result");
                //JsonObject location = result.GetNamedObject("location");
                //{
                //    double latitude = location.GetNamedNumber("lat");
                //    double longitude = location.GetNamedNumber("lng");
                //}
                //结构化地址信息
                geocoder.formattedAddress = result.GetNamedString("formatted_address");
                //所在商圈信息
                geocoder.business = result.GetNamedString("business");
                //当前位置结合POI的语义化结构描述
                geocoder.sematicDescription = result.GetNamedString("sematic_description");
                //城市代码
                geocoder.cityCode   = (int)result.GetNamedNumber("cityCode");
                geocoder.componentJ = result.GetNamedObject("addressComponent");
                //JsonArray pois = result.GetNamedArray("pois");
                //JsonArray poiRegions = result.GetNamedArray("poiRegions");
            }
            return(geocoder);
        }
コード例 #2
0
        IEnumerator RequestAddress()
        {
            while (true)
            {
                var position = transform.position;
                if (Vector3.Distance(position, _lastPosition) > DistanceThreshold)
                {
                    _lastPosition = position;
                    _geoCoder
                    .Search(GeoUtils.ToGeoCoordinate(_startCoordinate, position.x, position.z))
                    .Subscribe(r => _currentAddress = r);
                }

                yield return(new WaitForSeconds(UpdateFrequencyInSeconds));
            }
        }
コード例 #3
0
        /// <summary>
        /// 地理位置解析
        /// 传入详细地址,返回地址经纬度信息
        /// </summary>
        /// <param name="address">详细地址</param>
        /// <param name="city">城市名称,用于精确查找,可以不传</param>
        /// <return>解析后的结果</return>
        /// <remarks>2013-08-27 黄波 创建</remarks>
        /// <remarks>2013-12-13 邵斌 优化百度API调用返回空的情况</remarks>
        public GeocoderResult Geocoder(string address, string city = "")
        {
            GeocoderResult returnValue = null;
            var            apiURL      = string.Format("http://api.map.baidu.com/geocoder/v2/?address={0}&city={1}&ak={2}&output={3}"
                                                       , HttpUtility.UrlEncode(address.Trim())
                                                       , HttpUtility.UrlEncode(city.Trim())
                                                       , Constant.BAIDU_MAP_AK
                                                       , "json");

            try
            {
                var webRequest  = HttpWebRequest.Create(apiURL);
                var webResponse = (HttpWebResponse)webRequest.GetResponse();
                var stream      = new StreamReader(webResponse.GetResponseStream());
                var jsonStr     = stream.ReadToEnd();
                var jsonObject  = JObject.Parse(jsonStr);

                // 2013-12-13 邵斌 优化百度API调用返回空的情况
                if (jsonObject != null)
                {
                    //API说明 http://developer.baidu.com/map/webservice-geocoding.htm#.E6.8E.A5.E5.8F.A3.E5.8F.82.E6.95.B6
                    if ((jsonObject.Property("status") != null && jsonObject["status"].ToString() == "0") &&
                        jsonObject["result"]["location"] != null)
                    {
                        returnValue = new GeocoderResult
                        {
                            Confidence = Convert.ToInt32(jsonObject["result"]["confidence"].ToString()),
                            Lat        = Convert.ToDouble(jsonObject["result"]["location"]["lat"].ToString()),
                            Lng        = Convert.ToDouble(jsonObject["result"]["location"]["lng"].ToString()),
                            Level      = jsonObject["result"]["level"].ToString(),
                            Precise    = Convert.ToInt32(jsonObject["result"]["precise"].ToString()),
                            Status     = Convert.ToInt32(jsonObject["status"].ToString())
                        };
                    }
                    else
                    {
                        //TODO:API返回状态错误
                    }
                }
            }
            catch (Exception ex)
            {
                Log.SysLog.Instance.Error(Model.WorkflowStatus.LogStatus.系统日志来源.外部应用, ex.Message, ex);
            }
            return(returnValue);
        }
コード例 #4
0
        private void ProcessResult(GeocoderResult result)
        {
            var location = GetLocation(result.Element);

            var distanceToNewPlace = location.HasValue
                ? GeoUtils.Distance(location.Value, _coordinate)
                : 50; // NOTE give element some weight as we don't know its geometry

            var distanceToOldPlace = _currentLocation.HasValue
                ? GeoUtils.Distance(_currentLocation.Value, _coordinate)
                : float.MaxValue;

            if (location.HasValue && distanceToNewPlace <= distanceToOldPlace)
            {
                _text.text       = result.DisplayName;
                _currentLocation = location.Value;
            }
        }
コード例 #5
0
ファイル: StrokeSummary.xaml.cs プロジェクト: qq1257/Hello
        private async System.Threading.Tasks.Task <GeocoderResult> getGPS(TravelGPS gps, int tableId)
        {
            GeocoderResult geocoder = null;

            if (gps.address == null && gps.laitude != 200 && gps.longitude != 200)
            {
                geocoder = await getHttp(gps.laitude, gps.longitude);

                if (geocoder != null)
                {
                    dm.updataGPS(tableId, gps.ID, geocoder.formattedAddress, geocoder.business, geocoder.cityCode, geocoder.sematicDescription, geocoder.componentJ.Stringify());
                }
            }
            else if (gps.address != null)
            {
                geocoder = new GeocoderResult();
                geocoder.formattedAddress   = gps.address;
                geocoder.sematicDescription = gps.description;
            }
            return(geocoder);
        }