- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
$(document).ready(function(){ var destination = ''; var -6ren">
是否有可能在执行 setDirections() 时获得回调?
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&libraries=places&language=<?=SYS_LANG;?>"></script>
<script type="text/javascript">
$(document).ready(function(){
var destination = '<?=$_POST['address'];?>';
var directionsDisplay = new google.maps.DirectionsRenderer({ draggable: true });
var directionsService = new google.maps.DirectionsService();
var geocoder;
var infoWindowContent = '<div id="gmap_infowindow">infocontent</div>';
var map;
var marker;
var position = new google.maps.LatLng(46.80193957664, 11.41754150390625);
function calcRoute(start, end) {
var request = {
origin: start,
destination: end,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if(status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
function codeAddress(address) {
if(geocoder) {
geocoder.geocode({ 'address': address }, function(results, status) {
if(status == google.maps.GeocoderStatus.OK) {
calcRoute(results[0].geometry.location, position);
document.getElementById('gmap_input').value = address;
}
});
}
}
function initialize() {
if(destination) geocoder = new google.maps.Geocoder();
map = new google.maps.Map(document.getElementById('gmap_map'), {
center: new google.maps.LatLng(46.80193957664, 11.41754150390625),
zoom: 9,
mapTypeId: google.maps.MapTypeId.TERRAIN
});
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById("gmap_directions"));
var autocomplete = new google.maps.places.Autocomplete(document.getElementById('gmap_input'));
autocomplete.bindTo('bounds', map);
var infowindow = new google.maps.InfoWindow({ maxWidth: 240 });
var marker = new google.maps.Marker({
position: position,
map: map,
title:"Title"
});
infowindow.setContent(infoWindowContent);
infowindow.open(map, marker);
if(destination) codeAddress(destination);
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});
google.maps.event.addListener(autocomplete, 'place_changed', function() {
var place = autocomplete.getPlace();
if (place.geometry.viewport) {
map.fitBounds(place.geometry.viewport);
} else {
map.setCenter(place.geometry.location);
}
calcRoute(place.geometry.location, position);
});
google.maps.event.addListener(directionsDisplay, 'directions_changed', function() {
$('#article').mCustomScrollbar('vertical', 350, 'easeOutCirc', 1.05, 'auto', 'yes', 'no', false);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
$('#gmap_map').css('height', '310px');
$('#article form').submit(function(event){ event.preventDefault(); });
});
</script>
最佳答案
您可以将 directions_changed
的 EventListener 绑定(bind)到您的方向显示:
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer({ 'map': map });
//...
var request = {
origin : ...,
destination: ...,
travelMode : google.maps.DirectionsTravelMode.WALKING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
// ...
google.maps.event.addListener(directionsDisplay, 'directions_changed', function() {
// ... CALLBACK
});
这就是你想要的吗?
关于javascript - 谷歌地图 V3 setDirections() 回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7228400/
是否有可能在执行 setDirections() 时获得回调? "> $(document).ready(function(){ var destination = ''; var
我正在编写 Robocode,现在我有一个编码问题: 我定义了类Enemy来存储敌人信息(例如航向、方位、速度等),在这个类中我还定义了一个名为direction的私有(private)属性。然后我使
我使用 Google Maps API 构建了一个 map ,该 map 将根据来自 'whereNew.js' 的经度和纬度绘制点,标记的颜色将取决于来自 'MarketData.js' 的另一个参
我是使用 Google Maps API 的初学者,我只想就我的以下错误寻求一些帮助: Uncaught TypeError: Cannot read property 'setDirections'
本文整理了Java中us.ihmc.robotics.math.trajectories.YoPolynomial.setDirectly()方法的一些代码示例,展示了YoPolynomial.set
我是一名优秀的程序员,十分优秀!