2016-07-23 48 views
-1

我們需要發送一個googlemap多邊形作爲查詢字符串參數。我們在Rightmove.co.uk和其他網站上注意到,多邊形參數是經過編碼的。例如,三邊多邊形編碼爲多邊形= qntyHnjq%40jhAyv%40k%5CduC。這是發送多邊形作爲查詢字符串參數的特殊標準。如何將多邊形編碼爲這種格式。在Querystring中發送googlemap多邊形

非常感謝

回答

1

一種選擇是使用Google Maps JavaScript API v3使用的編碼算法。

我的問題的答案:Directions API overview_polyline doesn't have correct points包含關於算法的一些信息鏈接:

https://web.archive.org/web/20131122011459/http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/

快速測試與您提供的編碼字符串產生布倫特公園三角形,英國(西北的倫敦)。

代碼片段:

function initialize() { 
 
    var map = new google.maps.Map(
 
    document.getElementById("map_canvas"), { 
 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
 
    }); 
 
    var polygonStr = "qntyHnjq%40jhAyv%40k%5CduC"; 
 
    var unencodedPolypath = decodeURIComponent(polygonStr); 
 
    console.log(unencodedPolypath); 
 
    var polygon = new google.maps.Polygon({ 
 
    map: map, 
 
    path: google.maps.geometry.encoding.decodePath(unencodedPolypath) 
 
    }); 
 
    var bounds = new google.maps.LatLngBounds(); 
 
    for (var i = 0; i < polygon.getPaths().getAt(0).getLength(); i++) { 
 
    bounds.extend(polygon.getPaths().getAt(0).getAt(i)); 
 
    } 
 
    map.fitBounds(bounds); 
 

 
} 
 
google.maps.event.addDomListener(window, "load", initialize);
html, 
 
body, 
 
#map_canvas { 
 
    height: 100%; 
 
    width: 100%; 
 
    margin: 0px; 
 
    padding: 0px 
 
}
<script src="https://maps.googleapis.com/maps/api/js?libraries=geometry"></script> 
 
<div id="map_canvas"></div>

+0

你會如何服務器進行搜索應用程序的解碼此。你知道任何C#庫嗎?非常感謝。 – user2981411

相關問題