我可以修改此代码以检测Google Maps API中是否提供街景图像吗? [英] Can I modify this code to detect whether a street view image is available in Google Maps API?

查看:59
本文介绍了我可以修改此代码以检测Google Maps API中是否提供街景图像吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须承认,我使用Google Maps API对其做了一些说明.很多复制和粘贴以及基本编辑.除非没有街景图像,否则此代码非常有效.什么是检测不到图像并隐藏Pano div的最简单方法?或者反过来说,如果有图片则显示它:

I have to admit, I wing it a bit with Google Maps API. A lot of copy and pasting and basic edits. This code works really well unless a street view image is not available. What is the easiest way to detect no image and hid the pano div? Or the other way round, display it if there is an image:

    function googleMap() {

       var geocoder = new google.maps.Geocoder();

          if (geocoder) {
              alert('<?php echo $phoneDirectory->Address; ?>');
             geocoder.geocode({ 'address': '<?php echo $phoneDirectory->Address; ?>' }, function (results, status) {
                if (status == google.maps.GeocoderStatus.OK) {


                  var googleLat = results[0].geometry.location.lat();
                  var googleLong = results[0].geometry.location.lng();
                  //alert(googleLat + ", " + googleLong);


                var fenway = new google.maps.LatLng(googleLat,googleLong);
                var mapOptions = {
                    center: fenway,
                    zoom: 14,
                    mapTypeId: google.maps.MapTypeId.ROADMAP
                };

                var map = new google.maps.Map(
                    document.getElementById('map_canvas'), mapOptions);
                    var panoramaOptions = {
                        position: fenway,
                        pov: {
                        heading: 0,
                        pitch: 0
                    }
                };

                var panorama = new  google.maps.StreetViewPanorama(document.getElementById('pano'),panoramaOptions);
                map.setStreetView(panorama);

                // **** ADDED TO GET WORKING!!! ***** 
                var client = new google.maps.StreetViewService();
                client.getPanoramaByLocation(fenway, 50, function(result, status) {
                    if (status == "ZERO_RESULTS") {

                        // Hide street view div
                        $('#pano').css("display", "none");


                    }

                });     

                googleMapLoaded = true;


                } 
                else {
                  alert('No results found: ' + status);
                }
             });
          }         

}

推荐答案

选中此

如果附近没有全景,则结果为 ZERO_RESULTS

If there are no nearby panoramas the result is ZERO_RESULTS

这篇关于我可以修改此代码以检测Google Maps API中是否提供街景图像吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆