我想找到 Istanbul 尔两点之间的路线。为此,我尝试运行一个取自 this guide 的简单代码。 。但这段代码不起作用。我无法查看路线路径或 map 。我的代码在这里。
<title>Quick start. Publishing an interactive map on a page</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://api-maps.yandex.ru/2.0-stable/?load=package.standard&lang=ru-RU" type="text/javascript"></script>
<script src="http://yandex.st/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
var ymap;
ymaps.ready(function(){
ymap = new ymaps.Map ("map", {
center: [41.01771, 28.968484],
zoom: 10,
controls: ['zoomControl', 'typeSelector',
'geolocationControl', 'trafficControl',
'fullscreenControl']
});
ymaps.route([
'Maltepe',
'Kartal'
]).then(function (route){
ymap.geoObjects.add(route);
}, function(error){
alert("Ошибка. " + error.status +
":" + error.message);
}
);
});
</script>
最佳答案
示例中的代码是正确的。这是需要修复的页面。
您必须将正确定位/大小的 DIV 元素添加到页面的 HTML 中。该元素(“map”)的 id 作为第一个参数传递给构造函数 new ymaps.Map
。
这是一个简约的 HTML 和 CSS 代码:
HTML
<script src="http://api-maps.yandex.ru/2.1/?lang=ru_RU" type="text/javascript"></script>
<div id="map"></div>
CSS:
body {
height: 100%;
}
#map {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
我为您创建了一个实例,请参阅 this fiddle
关于javascript - Yandex Maps Api 示例不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28435908/