Javascript 我能';我得不到谷歌&x27;s Places服务&x27;s输出
在我的代码中,首先,我试图通过谷歌地图上的地理定位服务找到用户的位置 第二,我试图用谷歌的places服务在用户位置附近展示“酒吧”,比如你们去喝酒的地方。它应该在用户位置附近的“栏”上放置标记 然而这不起作用,我遇到了一个问题。但我不知道那是什么。它打开地图时,我的位置附近没有“栏” 我的css代码:Javascript 我能';我得不到谷歌&x27;s Places服务&x27;s输出,javascript,google-maps,google-maps-api-3,geolocation,Javascript,Google Maps,Google Maps Api 3,Geolocation,在我的代码中,首先,我试图通过谷歌地图上的地理定位服务找到用户的位置 第二,我试图用谷歌的places服务在用户位置附近展示“酒吧”,比如你们去喝酒的地方。它应该在用户位置附近的“栏”上放置标记 然而这不起作用,我遇到了一个问题。但我不知道那是什么。它打开地图时,我的位置附近没有“栏” 我的css代码: html, body { height: 100%; margin: 0; padding: 0; } #map_canvas { height: 100%; } @medi
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map_canvas {
height: 100%;
}
@media print {
html, body {
height: auto;
}
#map_canvas {
height: 650px;
}
}
这是我的javascript和HTML代码=
<!DOCTYPE html>
<html>
<head>
<title>Google Maps JavaScript API v3 Example: Map Geolocation</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="UTF-8">
<link href="mapcss.css" rel="stylesheet" type="text/css">
<!--
Include the maps javascript with sensor=true because this code is using a
sensor (a GPS locator) to determine the user's location.
See: http://code.google.com/apis/maps/documentation/javascript/basics.html#SpecifyingSensor
-->
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
<script type="text/javascript">
var map;
function initialize() {
var myOptions = {
zoom: 6,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map_canvas'),
myOptions);
// Try HTML5 geolocation
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = new google.maps.LatLng(position.coords.latitude,
position.coords.longitude);
var infowindow = new google.maps.InfoWindow({
map: map,
position: pos,
content: 'Location found using HTML5.'
});
map.setCenter(pos);
var request = {
location: pos,
radius: 500,
types: ['bar']
};
infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.search(request, callback);
},
function() {
handleNoGeolocation(true);
});
} else {
// Browser doesn't support Geolocation
handleNoGeolocation(false);
}
}
function handleNoGeolocation(errorFlag) {
if (errorFlag) {
var content = 'Error: The Geolocation service failed.';
} else {
var content = 'Error: Your browser doesn\'t support geolocation.';
}
var options = {
map: map,
position: new google.maps.LatLng(45.4643898,9.1883469),
content: content
};
var infowindow = new google.maps.InfoWindow(options);
map.setCenter(options.position);
}
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
createMarker(results[i]);
}
}
}
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() {
infowindow.setContent(place.name);
infowindow.open(map, this);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map_canvas"></div>
</body>
</html>
谷歌地图JavaScript API v3示例:地图地理位置
var映射;
函数初始化(){
变量myOptions={
缩放:6,
mapTypeId:google.maps.mapTypeId.ROADMAP
};
map=new google.maps.map(document.getElementById('map_canvas'),
肌肽);
//试试HTML5地理定位
if(导航器.地理位置){
navigator.geolocation.getCurrentPosition(函数(位置){
var pos=新的google.maps.LatLng(position.coords.latitude,
位置坐标经度);
var infowindow=new google.maps.infowindow({
地图:地图,
职位:pos,,
内容:“使用HTML5找到的位置。”
});
地图设置中心(pos);
var请求={
地点:pos,,
半径:500,
类型:['bar']
};
infowindow=new google.maps.infowindow();
var service=newgoogle.maps.places.PlacesService(地图);
服务搜索(请求、回调);
},
函数(){
手持导航(真);
});
}否则{
//浏览器不支持地理位置
手动定位(假);
}
}
函数handleNogeLocation(errorFlag){
如果(错误标志){
var content='错误:地理位置服务失败';
}否则{
var content='错误:您的浏览器不支持地理位置';
}
变量选项={
地图:地图,
位置:新google.maps.LatLng(45.4643898,9.1883469),
内容:内容
};
var infowindow=new google.maps.infowindow(选项);
地图设置中心(选项位置);
}
函数回调(结果、状态){
if(status==google.maps.places.PlacesServiceStatus.OK){
对于(var i=0;i
Google Places搜索结果通常是空的,特别是考虑到Google Places数据库在当前(或是我上次尝试时)是多么的稀疏。有关更多详细信息和建议,请参阅。Google Places搜索结果通常为空,特别是考虑到Google Places数据库在当前(或上次尝试时)的稀疏程度。有关更多详细信息和建议,请参阅。您确实需要接受以前问题的正确答案。好的,我接受这就是我更正并重做的原因。您确实需要接受以前问题的正确答案。好的,我接受这就是我更正并重做的原因。