为啥我的代码不起作用? [关闭]
Posted
技术标签:
【中文标题】为啥我的代码不起作用? [关闭]【英文标题】:why my code isn't working? [closed]为什么我的代码不起作用? [关闭] 【发布时间】:2014-08-31 06:16:47 【问题描述】:<html>
<head>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true&libraries=places"></script>
<script>
var infowindow,
placemarkers = [];
function placeSearch(map, request)
var map = map;
var service = new google.maps.places.PlacesService(map);
service.search(request,
function (results, status)
if (status == google.maps.places.PlacesServiceStatus.OK)
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < results.length; ++i)
bounds.extend(results[i].geometry.location);
placemarkers.push(createMarker(results[i].geometry.location,
map,
'http://labs.google.com/ridefinder/images/mm_20_orange.png',
results[i].name,
false,
fnc: function ()
infowindow.open();
));
map.fitBounds(bounds);
);
function createMarker(latlng, map, icon, content, center, action)
var marker = new google.maps.Marker(
map: map,
position: latlng,
content: content
);
if (icon)
marker.setIcon(icon);
if (center)
map.setCenter(latlng);
google.maps.event.addListener(marker, 'click', function ()
infowindow.setContent(this.content);
infowindow.open(map, this);
);
if (action)
action.fnc(map, action.args);
return marker;
function initialize()
var location = new google.maps.LatLng(-33.8665433, 151.1956316),
map = new google.maps.Map(document.getElementById('map'),
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: location,
zoom: 15
);
infowindow = new google.maps.InfoWindow();
navigator.geolocation.getCurrentPosition(function (place)
createMarker(
new google.maps.LatLng(place.coords.latitude,
place.coords.longitude),
map,
null,
'your current position',
true,
fnc: placeSearch,
args:
radius: 5000,
types: ['restaurant'],
location: new google.maps.LatLng(place.coords.latitude,
place.coords.longitude)
);
);
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>
【问题讨论】:
具体的问题是什么?即你的代码的一些描述会很好。 它没有显示任何东西:( 【参考方案1】:你需要调用你的初始化函数,就这样调用它
initialize()
Ckech the JS Fiddle Example
【讨论】:
以上是关于为啥我的代码不起作用? [关闭]的主要内容,如果未能解决你的问题,请参考以下文章