题
我工作的一个配置文件,网站,显示了使用谷歌地图的人的位置。
我实现了谷歌地图,现在,它显示了你的人正在查看的生活和你住的地方。
的代码是在这里:
var map = null;
var geocoder = null;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GScaleControl());
map.addControl(new GMapTypeControl());
geocoder = new GClientGeocoder();
}
}
function showAddresses(address1,address2) {
if (geocoder) {
geocoder.getLatLng(
address1,
function(point) {
if (!point) {
alert(address1 + " not found");
} else {
map.setCenter(point, 13);
var marker = new GMarker(point);
map.addOverlay(marker);
marker.openInfoWindowHtml(address1);
}
}
);
geocoder.getLatLng(
address2,
function(point) {
if (!point) {
alert(address2 + " not found");
} else {
map.setCenter(point, 13);
var marker = new GMarker(point);
map.addOverlay(marker);
}
}
);
}
}
但是,它没有做什么,就是修改缩放级别时,2位是如此遥远,他们不适合在地图上togheter。我不知道如何解决。
在接下来的步骤是,我想有地图显示两个点,它们之间的距离之间的视觉路线以下是route.I've试图在谷歌地图网站的时候,我知道自己有这个功能。我无法找到如何实现它的任何文件。
或者它会更好只是为了让那去谷歌地图,给你准备好的页面的超链接?这也是我不知道怎么办。
解决方案
从未做过,但看到GDirections对象在API:
http://code.google.com/apis/maps /documentation/reference.html#GDirections
Loooks像你所寻找的。什么
其他提示
所有点添加到一个多边形。从多边形,得到LatLongBounds,其可以被用来导出缩放级别。
private function setMapZoomLevelBasedOnPlottedPoints(polygonPoints:Array):void
{
var pointBounds:LatLngBounds = getLatLongBounds(polygonPoints);
_map.setCenter(pointBounds.getCenter());
_map.setZoom(_map.getBoundsZoomLevel(pointBounds) - 1);
}
private function getLatLongBounds(polygonPoints:Array):LatLngBounds
{
for(var i:Number; i < polygonPoints; i++)
{
polygonPoints.push(polygonPoints[i] as LatLong);
}
var polygon:IPolygon = new Polygon(polygonPoints);
return polygon.getLatLngBounds();
}
这是API英寸你可以找到它
route site:http://code.google.com/apis/maps
下面是一个页面,例如,示出了在与Flash覆盖“驱动器的方向”。该API是一个有点不同,当您闪光灯之外做的地图,却是相同的基本代码。 http://code.google.com/apis/maps/documentation/闪光灯/ services.html
我做了MapQuest的更多的工作,所以我刚刚进入谷歌地图API。
不隶属于 StackOverflow