1. 程式人生 > >高德地圖GPS經緯度轉高德經緯度

高德地圖GPS經緯度轉高德經緯度

 //此ajax將gps經緯度轉換為高德經緯度。其中根據個人需要填寫相應引數
                    $.ajax({

                        type: 'GET',
                        async: false, //此標記標示同步
                        url: 'http://restapi.amap.com/v3/assistant/coordinate/convert?key=736ee15f242085b54b92927303b7752b&locations=' + alldata[i].illegalEndLonLat + '&coordsys=gps',
                        dataType: 'json',

                        success: function (resdata) {
                            locations = resdata.locations;
                            
                            if (resdata.status == 0) {
                                LoginTimeout('伺服器超時!');
                            } else {
                                $.ajax({

                                    type: 'POST',
                                    async: false, //此標記標示同步
                                    url: 'http://restapi.amap.com/v3/geocode/regeo?key=736ee15f242085b54b92927303b7752b&location=' + locations + '&poitype=商務寫字樓&radius=1000&extensions=all&batch=false&roadlevel=0',
                                    dataType: 'json',

                                    success: function (resdata) {
                                        //alert(resdata.regeocode);
                                        if (resdata.state == 104) {
                                            LoginTimeout('伺服器超時!');
                                        }
                                        if (resdata.regeocode != null && resdata.regeocode != "") {

                                            var arr = resdata;
                                            //alert(eval(resdata.regeocode).formatted_address);
                                            alldata[i].illegalEndLonLat = eval(resdata.regeocode).formatted_address;
                                        } else {

                                        }

                                    }
                                });
                            }
                            

                        }

                    });

**************************************************後臺GPS經緯度轉高德經緯度


        //===================================start這個是gps經緯度轉換高德的經緯度=============================
   

        public static string SendRequest(String url, Encoding encoding)
        {
            System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
            webRequest.Method = "GET";
            System.Net.HttpWebResponse webResponse = (System.Net.HttpWebResponse)webRequest.GetResponse();
            System.IO.StreamReader sr = new System.IO.StreamReader(webResponse.GetResponseStream(), encoding);
            return sr.ReadToEnd();
        }


        //===================================start這個是gps經緯度轉換高德的經緯度=============================





//gps經緯度轉高德經緯度
                    String url = "http://restapi.amap.com/v3/assistant/coordinate/convert?locations=" + location + "&coordsys=gps&output=xml&key=d8440a22fb3fc04b72a61aa6b51902a2";
                    String locationTwo = SendRequest(url, Encoding.UTF8);
int IndexofA = sss.IndexOf("<locations>");
int IndexofB = sss.IndexOf("</locations>");
     sssssss = sss.Substring(IndexofA + 11, IndexofB - IndexofA - 11);