私のページには次のコードがあります (現時点では Google の例に基づいています。しかし、問題が発生しました。場所を機能させることができないようです (マーカーは表示されません)。これは私のコードです . . はずですユーザーの現在地から 10 km 以内にあるすべてのカフェ、レストラン、ダールを地理位置情報とともに表示し、ユーザーの現在位置からオーストラリアのダーウィンへの道順も示します。
これはコードです:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Google Maps JavaScript API v3 Example: Directions Complex</title>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map_canvas {
height: 650px;
}
#directions-panel {
height: 100%;
float: right;
width: 390px;
overflow: auto;
}
#map-canvas {
margin-right: 400px;
}
#control {
background: #fff;
padding: 5px;
font-size: 14px;
font-family: Arial;
border: 1px solid #ccc;
box-shadow: 0 2px 2px rgba(33, 33, 33, 0.4);
display: none;
}
@media print {
#map-canvas {
height: 500px;
margin: 0;
}
#directions-panel {
float: none;
width: auto;
}
}
.gmnoprint {display:none;}
</style>
<script src="https://maps.googleapis.com/maps/api/js?sensor=true&libraries=places"></script>
<script>
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var a;
var b;
var latandlon;
function initialize()
{
navigator.geolocation.getCurrentPosition(create_a_var);
}
function create_a_var(position)
{
a = position.coords.latitude;
b = position.coords.longitude;
latandlon = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
loadmapscript();
}
function loadmapscript() {
directionsDisplay = new google.maps.DirectionsRenderer();
var mapOptions = {
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: new google.maps.LatLng(a, b),
disableDefaultUI: true
};
var map = new google.maps.Map(document.getElementById('map_canvas'),
mapOptions);
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById('directions-panel'));
var control = document.getElementById('control');
control.style.display = 'block';
map.controls[google.maps.ControlPosition.TOP].push(control);
var request = {
location: latandlon,
radius: 10000,
types: ['bar', 'restaurant', 'cafe']
};
}
function calcRoute() {
var start = latandlon;
var end = "Darwin, NT, Australia";
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 createMarker(place) {
var placeLoc = place.geometry.location;
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location
});
google.maps.event.addListener(marker, 'click', function() {
alert(place.name);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="control">
<strong>Start:</strong>
<button id="start" onclick="calcRoute();">Click Me Please :)</button>
</div>
<div id="directions-panel"></div>
<div id="map_canvas"></div>
</body>
</html>
var directionDisplay; var directionService = new google.maps.DirectionsService(); 変数 a; 変数 b; var latandlon; 変数マップ; function initialize() { navigator.geolocation.getCurrentPosition(create_a_var); }
function create_a_var(position) { a = position.coords.latitude; b = position.coords.longitude; latandlon = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); loadmapscript(); } function loadmapscript() { directionsDisplay = new google.maps.DirectionsRenderer(); var mapOptions = { zoom: 15, mapTypeId: google.maps.MapTypeId.ROADMAP, center: new google.maps.LatLng(a, b), disableDefaultUI: true }; map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions); directionsDisplay.setMap(map); directionsDisplay.setPanel(document.getElementById('directions-panel')); var control = document.getElementById('control'); control.style.display = 'block'; map.controls[google.maps.ControlPosition.TOP].push(control); var request2 = { location: latandlon, radius: 10000, types: ['bar', 'restaurant', 'cafe'] }; } function calcRoute() { var start = latandlon; var end = "Darwin, NT, Australia"; 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 createMarker(place) { var placeLoc = place.geometry.location; var marker = new google.maps.Marker({ map: map, position: place.geometry.location }); google.maps.event.addListener(marker, 'click', function() { alert(place.name); }); } google.maps.event.addDomListener(window, 'load', initialize);