本文介绍了Google地图突出显示特定区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何突出显示Google地图中的特定区域?如果您转到maps.google.com并搜索您的位置,虚线将突出显示该区域。如何在Google Maps API中执行相同的操作?
How to highlight a particular area in Google Maps? If you go to maps.google.com and search for your location, a dotted line will highlight the area. How to do the same in Google maps API?
推荐答案
您想在地图上的某个区域绘制一条线?使用
You want to draw a line around an area on a map? Use the Polyline class
更新:如果您想要
Update: if you want a nicely styled semi-transparent overlay like the neighbourhood examples on http://zumper.com you should use the Polygon class
下面是他们的JS示例,它应该让你知道他们是如何做的。
Here's a sample of their JS which should give you an idea how they're doing it.
makeHood: function (hood, hoodId) {
var hoodPoly = HOOD_CACHE[hoodId];
if (hoodPoly) {
hoodPoly.setOptions(hoodPolyStandardOptions)
} else {
var coordinates = [];
var markerBounds = hood["bounds"][0]["exterior"];
for (var i = 0, len = markerBounds.length; i < len; ++i) {
coordinates.push(new google.maps.LatLng(markerBounds[i][3], markerBounds[i][0]))
}
var options = angular.copy(hoodPolyInitialOptions);
options.paths = coordinates;
hoodPoly = new google.maps.Polygon(options);
hoodPoly.name = hood["name"];
hoodPoly.id = hoodId;
hoodPoly.point = new google.maps.LatLng(hood["lat"], hood["lng"]);
hoodPoly.mouseoverOptions = hoodPolyMouseoverOptions;
hoodPoly.standardOptions = hoodPolyStandardOptions;
var box = hood["box"];
hoodPoly.box = new google.maps.LatLngBounds(new google.maps.LatLng(box[1], box[0]), new google.maps.LatLng(box[3], box[2]));
hoodPoly.getPosition = angular.bind(hoodPoly, function () {
return this.point
});
HOOD_CACHE[hoodId] = hoodPoly
}
hoodPoly.hood = hood;
return hoodPoly
},
这篇关于Google地图突出显示特定区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!