Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 谷歌API v3标记没有出现_Javascript_Google Maps_Google Maps Markers - Fatal编程技术网

Javascript 谷歌API v3标记没有出现

Javascript 谷歌API v3标记没有出现,javascript,google-maps,google-maps-markers,Javascript,Google Maps,Google Maps Markers,我的标记没有显示在附近搜索的结果中。有人能帮忙吗?我对javascript和谷歌api非常熟悉。 我基本上是想找到这个地区所有的麦当劳。显示的唯一标记是用户的当前位置。提前谢谢!:D <!DOCTYPE HTML> <html> <head> <title>Basic GeoLocation Map</title> <!-- Google Maps and Places API -->

我的标记没有显示在附近搜索的结果中。有人能帮忙吗?我对javascript和谷歌api非常熟悉。 我基本上是想找到这个地区所有的麦当劳。显示的唯一标记是用户的当前位置。提前谢谢!:D

<!DOCTYPE HTML>
<html>

    <head>
        <title>Basic GeoLocation Map</title>
        <!-- Google Maps and Places API -->
        <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&amp;sensor=false"></script>
        <!-- jQuery -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
        <script type="text/javascript">
            function initGeolocation() {
                if (navigator.geolocation) {

                    // Call getCurrentPosition with success and failure callbacks
                    navigator.geolocation.getCurrentPosition(success, fail);
                } else {
                    alert("Sorry, your browser does not support geolocation services.");
                }
            }
            var map;
            var service;

            function handleSearchResults(results, status) {
                console.log(results);

                for (var i = 0; i < results, length; i++) {
                    var marker = new google.maps.Marker({
                        position: results(i).geometry.location,
                        map: map
                    });
                }

            }

            function performSearch() {
                var request = {
                    bounds: map.getBounds(),
                    name: "McDonald's"
                }

                service.nearbySearch(request, handleSearchResults);
            }

            function success(position) {
                // Define the coordinates as a Google Maps LatLng Object
                var coords = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

                // Prepare the map options
                var mapOptions = {
                    zoom: 14,
                    center: coords,
                    mapTypeControl: false,
                    navigationControlOptions: {
                        style: google.maps.NavigationControlStyle.SMALL
                    },
                    mapTypeId: google.maps.MapTypeId.ROADMAP
                };

                // Create the map, and place it in the map_canvas div
                map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);


                // Place the initial marker
                var marker = new google.maps.Marker({
                    position: coords,
                    map: map,
                    title: "Your current location!"
                });
                marker.setMap(map);

                service = new google.maps.places.PlacesService(map);

                google.maps.event.addListenerOnce(map, 'bounds_changed', performSearch);
            }

            function fail() {
                // Could not obtain location
            }

             //Request places from Google

            function placesRequest(title, latlng, radius, types, icon) {
                //Parameters for our places request
                var request = {
                    location: latlng,
                    radius: radius,
                    types: types
                };
                //Make the service call to google
                var callPlaces = new google.maps.places.PlacesService(map);
                callPlaces.search(request, function (results, status) {
                    //trace what Google gives us back
                    $.each(results, function (i, place) {
                        var placeLoc = place.geometry.location;
                        var thisplace = new google.maps.Marker({
                            map: map,
                            position: place.geometry.location,
                            icon: icon,
                            title: place.name
                        });
                    })
                });

            }
        </script>
    </head>

    <body onload="initGeolocation();">
        <div style="position:absolute; width:380px; height: 100%; overflow:auto; float:left; padding-left:10px; padding-right:10px;">
             <h1>Google Places API</h1>

            <p>We're using both google places (to search for things in a certain category) AND google maps (to put the things on a map)~! PLUS we're using geolocatoin to automatically centre the map on the user's current location!</p>
        </div>
        <!-- map div container -->
        <div id="map_canvas" style="height:500px; margin-left:400px; border-right: 1px solid #666666; border-bottom: 1px solid #666666; border-top: 1px solid #AAAAAA; border-left: 1px solid #AAAAAA;"></div>
    </body>

</html>

基本地理位置图
函数initGeolocation(){
if(导航器.地理位置){
//使用成功和失败回调调用getCurrentPosition
navigator.geolocation.getCurrentPosition(成功,失败);
}否则{
警报(“对不起,您的浏览器不支持地理定位服务。”);
}
}
var映射;
var服务;
函数handleSearchResults(结果、状态){
控制台日志(结果);
对于(变量i=0;i

性能搜索(不正确使用)更改为

handleSearchResults
(某些打字错误)以

函数handleSearchResults(结果、状态){
对于(var i=0;i

…你的例子很有效。对我来说,返回附近的5家麦当劳:-)

错误控制台中有错误消息吗?没有,我也验证了它,但出现的唯一错误是“字符编码未声明”。继续使用windows-1252。'但我很确定这不涉及标记。啊,谢谢!:你太棒了!
function performSearch() {
  var request = {
    location: map.getCenter(),
    radius: 1500,
    name: ["McDonald's"]
  }
  service.nearbySearch(request, handleSearchResults);
}
function handleSearchResults(results, status) {
  for(var i = 0; i < results.length; i++) {
    var marker=new google.maps.Marker({
      position: results[i].geometry.location,
      map: map
    });
   }
}