Street View सेवा

खास जानकारी

प्लैटफ़ॉर्म चुनें: Android iOS JavaScript

Google Street View, अपनी कवरेज वाली जगहों के लिए तय की गई सड़कों से 360 डिग्री का खूबसूरत नज़ारा दिखाता है. Street View का एपीआई कवरेज, Google Maps ऐप्लिकेशन https://maps.google.com/ के लिए कवरेज जैसा ही है. फ़िलहाल, Street View के लिए जिन शहरों का इस्तेमाल किया जा सकता है उनकी सूची Google Maps की वेबसाइट पर दी गई है.

Street View इमेज का एक नमूना नीचे दिखाया गया है.


Maps JavaScript API, Google Maps के Street View में इस्तेमाल की गई तस्वीरें लेने और उन्हें इस्तेमाल करने का तरीका दिखाता है. यह Street View सेवा, ब्राउज़र में नेटिव तौर पर काम करती है.

Street View मैप के इस्तेमाल की जानकारी

हालांकि, Street View का इस्तेमाल स्टैंडअलोन DOM एलिमेंट में किया जा सकता है, लेकिन मैप में जगह की जानकारी देते समय, यह सबसे ज़्यादा फ़ायदेमंद होता है. डिफ़ॉल्ट रूप से, मैप पर Street View चालू होती है और Street View पेगमैन कंट्रोल, नेविगेशन (ज़ूम और पैन) कंट्रोल में दिखता है. मैप की MapOptions में इस कंट्रोल को छिपाया जा सकता है. इसके लिए, streetViewControl को false पर सेट करें. Map की streetViewControlOptions.position प्रॉपर्टी को ControlPosition पर सेट करके, Street View कंट्रोल की डिफ़ॉल्ट जगह भी बदली जा सकती है.

Street View पेगमैन कंट्रोल, आपको Street View के पैनोरामा सीधे मैप में देखने की सुविधा देता है. जब उपयोगकर्ता पेगमैन को क्लिक और होल्ड करता है, तो Street View की सुविधा वाली सड़कों के आस-पास की नीली आउटलाइन दिखाने के लिए मैप अपडेट किया जाता है. यह उपयोगकर्ता के लिए Google Maps ऐप्लिकेशन जैसा ही होता है.

जब उपयोगकर्ता किसी पेगमैन मार्कर को सड़क पर छोड़ता है, तो मैप अपडेट की गई जगह का Street View पैनोरामा दिखाने के लिए अपडेट होता है.

स्ट्रीट व्यू पैनोरामा

Street View इमेज में StreetViewPanorama ऑब्जेक्ट इस्तेमाल किए जा सकते हैं जो "व्यू" के Street View के लिए एपीआई इंटरफ़ेस को दिखाते हैं. हर मैप में एक डिफ़ॉल्ट 'स्ट्रीट व्यू' पैनोरामा होता है, जिसे आप मैप के getStreetView() तरीके को कॉल करके फिर से देख सकते हैं. जब आप किसी Street View कंट्रोल को मैप पर जोड़ने के लिए, streetViewControl विकल्प को true पर सेट करते हैं, तो इस पेगमैन कंट्रोल को डिफ़ॉल्ट Street View पैनोरामा से अपने-आप जोड़ देता है.

खुद का StreetViewPanorama ऑब्जेक्ट भी बनाया जा सकता है. साथ ही, मैप की streetView प्रॉपर्टी को बनाए गए ऑब्जेक्ट पर सेट करके, डिफ़ॉल्ट के बजाय मैप को सेट किया जा सकता है. अगर डिफ़ॉल्ट तौर पर सेट किए गए व्यवहार में बदलाव करना है, तो डिफ़ॉल्ट पैनोरामा को बदला जा सकता है. उदाहरण के लिए, मैप और पैनोरामा के बीच ओवरले का अपने-आप शेयर होना. (नीचे स्ट्रीट व्यू में ओवरले देखें.)

स्ट्रीट व्यू कंटेनर

इसके बजाय, आप StreetViewPanorama को किसी अलग DOM एलिमेंट में दिखाना चाहें, जो कि अक्सर <div> एलिमेंट हो. बस StreetViewPanorama के कंस्ट्रक्टर में डीओएम एलिमेंट पास करें. इमेज के सबसे अच्छे डिसप्ले के लिए, हमारा सुझाव है कि वह 200 पिक्सल x 200 पिक्सल का हो.

ध्यान दें: हालांकि, Street View की सुविधा को मैप के साथ इस्तेमाल करने के लिए डिज़ाइन किया गया है, लेकिन इसका इस्तेमाल करना ज़रूरी नहीं है. बिना मैप वाले स्टैंडअलोन Street View ऑब्जेक्ट का इस्तेमाल किया जा सकता है.

Street View की जगहें और पॉइंट ऑफ़ व्यू (पीओवी)

StreetViewPanorama कंस्ट्रक्टर, StreetViewOptions पैरामीटर का इस्तेमाल करके भी Street View की जगह और व्यू पॉइंट सेट करने की सुविधा देता है. ऑब्जेक्ट बनाने के बाद, उसकी जगह और POV बदलने के लिए, आपके पास उस ऑब्जेक्ट पर setPosition() और setPov() को कॉल करने का विकल्प होता है.

Street View की जगह की जानकारी से, किसी इमेज के लिए कैमरे के फ़ोकस की जगह पता चलती है. हालांकि, इससे उस इमेज के लिए कैमरे का ओरिएंटेशन तय नहीं होता है. इस मकसद के लिए StreetViewPov ऑब्जेक्ट दो प्रॉपर्टी के बारे में बताता है:

  • heading (डिफ़ॉल्ट 0) सही उत्तर से डिग्री में कैमरे के स्थान के चारों ओर रोटेशन कोण बताता है. शीर्षकों को घड़ी की दिशा में (90 डिग्री पूर्व में सही) मापा जाता है.
  • pitch (डिफ़ॉल्ट 0) कैमरे के शुरुआती डिफ़ॉल्ट पिच से ऐंगल वैरियंस "अप" या "डाउन" के बारे में बताता है, जो अक्सर (हमेशा नहीं) सपाट होता है. (उदाहरण के लिए, किसी पहाड़ी पर ली गई इमेज एक डिफ़ॉल्ट पिच दिखा सकती है, जो हॉरिज़ॉन्टल नहीं है.) पिच ऐंगल, पॉज़िटिव वैल्यू (डिफ़ॉल्ट पिच के लिए +90 डिग्री तक और सीधा या ऑर्थोगॉनल) और नीचे की तरफ़ देखने के लिए नेगेटिव वैल्यू (-90 डिग्री तक सीधा और सामान्य पिच तक) को मापा जाता है.

Street View कैमरे का व्यू तय करने के लिए, अक्सर StreetViewPov ऑब्जेक्ट का इस्तेमाल किया जाता है. आप StreetViewPanorama.getPhotographerPov() तरीके से भी फ़ोटोग्राफ़र के व्यू की दिशा तय कर सकते हैं. यह आम तौर पर कार या ट्राइक की दिशा में होता है.

इस कोड में, बोस्टन का मैप दिखाया गया है, जहां से फ़ेनवे पार्क का शुरुआती नज़ारा दिखता है. पेगमैन को चुनने और उसे मैप पर समर्थित स्थान पर खींचने से सड़क दृश्य पैनोरामा बदल जाएगा:

TypeScript

function initialize() {
  const fenway = { lat: 42.345573, lng: -71.098326 };
  const map = new google.maps.Map(
    document.getElementById("map") as HTMLElement,
    {
      center: fenway,
      zoom: 14,
    }
  );
  const panorama = new google.maps.StreetViewPanorama(
    document.getElementById("pano") as HTMLElement,
    {
      position: fenway,
      pov: {
        heading: 34,
        pitch: 10,
      },
    }
  );

  map.setStreetView(panorama);
}

declare global {
  interface Window {
    initialize: () => void;
  }
}
window.initialize = initialize;

JavaScript

function initialize() {
  const fenway = { lat: 42.345573, lng: -71.098326 };
  const map = new google.maps.Map(document.getElementById("map"), {
    center: fenway,
    zoom: 14,
  });
  const panorama = new google.maps.StreetViewPanorama(
    document.getElementById("pano"),
    {
      position: fenway,
      pov: {
        heading: 34,
        pitch: 10,
      },
    },
  );

  map.setStreetView(panorama);
}

window.initialize = initialize;

CSS

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}

#map,
#pano {
  float: left;
  height: 100%;
  width: 50%;
}

एचटीएमएल

<html>
  <head>
    <title>Street View split-map-panes</title>
    <script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>

    <link rel="stylesheet" type="text/css" href="./style.css" />
    <script type="module" src="./index.js"></script>
  </head>
  <body>
    <div id="map"></div>
    <div id="pano"></div>

    <!-- 
      The `defer` attribute causes the callback to execute after the full HTML
      document has been parsed. For non-blocking uses, avoiding race conditions,
      and consistent behavior across browsers, consider loading using Promises.
      See https://developers.google.com/maps/documentation/javascript/load-maps-js-api
      for more information.
      -->
    <script
      src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg&callback=initialize&v=weekly"
      defer
    ></script>
  </body>
</html>
उदाहरण देखें

सैंपल आज़माएं

मोबाइल डिवाइस पर मोशन ट्रैकिंग

जिन डिवाइस पर डिवाइस का ओरिएंटेशन इवेंट काम करते हैं उन पर एपीआई, उपयोगकर्ताओं को डिवाइस की हलचल के मुताबिक व्यू को बदलने की सुविधा देता है. उपयोगकर्ता अपने डिवाइसों को मूव करके आस-पास देख सकते हैं. इसे मोशन ट्रैकिंग या डिवाइस रोटेशन ट्रैकिंग कहा जाता है.

ऐप्लिकेशन डेवलपर के तौर पर, आप डिफ़ॉल्ट व्यवहार को इस तरह बदल सकते हैं:

  • मोशन ट्रैकिंग की सुविधा को चालू या बंद करें. जिस डिवाइस पर यह सुविधा काम करती है उस पर मोशन ट्रैकिंग डिफ़ॉल्ट रूप से चालू रहती है. नीचे दिया गया नमूना मोशन ट्रैकिंग को बंद कर देता है, लेकिन मोशन ट्रैकिंग का कंट्रोल नहीं दिखता. (ध्यान दें कि उपयोगकर्ता कंट्रोल पर टैप करके मोशन ट्रैकिंग की सुविधा चालू कर सकता है.)
    var panorama = new google.maps.StreetViewPanorama(
        document.getElementById('pano'), {
          position: {lat: 37.869260, lng: -122.254811},
          pov: {heading: 165, pitch: 0},
          motionTracking: false
        });
    
  • मोशन ट्रैकिंग कंट्रोल को छिपाएं या दिखाएं. डिफ़ॉल्ट रूप से यह कंट्रोल उन डिवाइसों पर दिखता है जो मोशन ट्रैकिंग के साथ काम करते हैं. मोशन ट्रैकिंग को चालू या बंद करने के लिए उपयोगकर्ता, कंट्रोल पर टैप कर सकता है. ध्यान दें कि अगर डिवाइस मोशन ट्रैकिंग के साथ काम नहीं करता है, तो कंट्रोल कभी नहीं दिखेगा. भले ही, motionTrackingControl की वैल्यू कुछ भी हो.

    नीचे दिया गया सैंपल, मोशन ट्रैकिंग और मोशन ट्रैकिंग कंट्रोल, दोनों को बंद करता है. इस मामले में, उपयोगकर्ता मोशन ट्रैकिंग को चालू नहीं कर सकता:

    var panorama = new google.maps.StreetViewPanorama(
        document.getElementById('pano'), {
          position: {lat: 37.869260, lng: -122.254811},
          pov: {heading: 165, pitch: 0},
          motionTracking: false,
          motionTrackingControl: false
        });
    
  • मोशन ट्रैकिंग कंट्रोल की डिफ़ॉल्ट जगह बदलें. डिफ़ॉल्ट रूप से, कंट्रोल पैनोरामा के सबसे नीचे दाईं ओर (स्थिति RIGHT_BOTTOM) के पास दिखता है. यह सैंपल, कंट्रोल की जगह को सबसे नीचे बाईं ओर सेट करता है:
    var panorama = new google.maps.StreetViewPanorama(
        document.getElementById('pano'), {
          position: {lat: 37.869260, lng: -122.254811},
          pov: {heading: 165, pitch: 0},
          motionTrackingControlOptions: {
            position: google.maps.ControlPosition.LEFT_BOTTOM
          }
        });
    

मोशन ट्रैकिंग को काम करने के लिए, मोबाइल डिवाइस (या डिवाइस ओरिएंटेशन इवेंट के साथ काम करने वाले किसी भी डिवाइस) पर यह नमूना देखें:


उदाहरण देखें

स्ट्रीट व्यू में ओवरले

StreetViewPanorama ऑब्जेक्ट, मैप के ओवरले नेटिव डिसप्ले के साथ काम करता है. ओवरले आम तौर पर "स्ट्रीट लेवल" पर दिखते हैं, जो LatLng पोज़िशन पर होते हैं. (उदाहरण के लिए, Street View पैनोरामा में मार्कर, पूंछ में जगह के हॉरिज़ॉन्टल प्लेन में दिखेंगे.)

फ़िलहाल, स्ट्रीट व्यू पैनोरामा पर काम करने वाले अलग-अलग तरह के ओवरले, Marker, InfoWindow, और कस्टम OverlayView पर ही दिखाए जा सकते हैं. मैप में दिखाए गए ओवरले को 'स्ट्रीट व्यू' के पैनोरामा में दिखाया जा सकता है. ऐसा करने के लिए, पैनोरामा को Map ऑब्जेक्ट का विकल्प मानकर, setMap() को कॉल किया जा सकता है. साथ ही, StreetViewPanorama को मैप के बजाय, आर्ग्युमेंट के तौर पर पास किया जा सकता है. इसी तरह, जानकारी देने वाली विंडो, open() को कॉल करके और मैप के बजाय StreetViewPanorama() को पास करके 'स्ट्रीट व्यू' के पैनोरामा में खोली जा सकती हैं.

इसके अलावा, डिफ़ॉल्ट StreetViewPanorama के साथ मैप बनाते समय, मैप पर बनाए गए सभी मार्कर, मैप से जुड़े Street View पैनोरामा के साथ अपने-आप शेयर हो जाते हैं, बशर्ते पैनोरामा दिख रहा हो. डिफ़ॉल्ट Street View पैनोरामा फिर से पाने के लिए, Map ऑब्जेक्ट पर getStreetView() को कॉल करें. ध्यान दें कि अगर आपने मैप की streetView प्रॉपर्टी को अपनी प्रॉपर्टी के StreetViewPanorama पर सेट किया है, तो डिफ़ॉल्ट पैनोरामा बदल जाएगा.

नीचे दिए गए उदाहरण में, एस्टर प्लेस, न्यूयॉर्क शहर के आस-पास की अलग-अलग जगहों को दिखाने वाले मार्कर दिखाए गए हैं. StreetViewPanorama में दिख रहे शेयर किए गए मार्कर दिखाने के लिए, डिसप्ले को Street View पर टॉगल करें.

TypeScript

let panorama: google.maps.StreetViewPanorama;

function initMap(): void {
  const astorPlace = { lat: 40.729884, lng: -73.990988 };

  // Set up the map
  const map = new google.maps.Map(
    document.getElementById("map") as HTMLElement,
    {
      center: astorPlace,
      zoom: 18,
      streetViewControl: false,
    }
  );

  document
    .getElementById("toggle")!
    .addEventListener("click", toggleStreetView);

  // Set up the markers on the map
  const cafeMarker = new google.maps.Marker({
    position: { lat: 40.730031, lng: -73.991428 },
    map,
    icon: "https://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=cafe|FFFF00",
    title: "Cafe",
  });

  const bankMarker = new google.maps.Marker({
    position: { lat: 40.729681, lng: -73.991138 },
    map,
    icon: "https://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=dollar|FFFF00",
    title: "Bank",
  });

  const busMarker = new google.maps.Marker({
    position: { lat: 40.729559, lng: -73.990741 },
    map,
    icon: "https://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=bus|FFFF00",
    title: "Bus Stop",
  });

  // We get the map's default panorama and set up some defaults.
  // Note that we don't yet set it visible.
  panorama = map.getStreetView()!; // TODO fix type
  panorama.setPosition(astorPlace);
  panorama.setPov(
    /** @type {google.maps.StreetViewPov} */ {
      heading: 265,
      pitch: 0,
    }
  );
}

function toggleStreetView(): void {
  const toggle = panorama.getVisible();

  if (toggle == false) {
    panorama.setVisible(true);
  } else {
    panorama.setVisible(false);
  }
}

declare global {
  interface Window {
    initMap: () => void;
  }
}
window.initMap = initMap;

JavaScript

let panorama;

function initMap() {
  const astorPlace = { lat: 40.729884, lng: -73.990988 };
  // Set up the map
  const map = new google.maps.Map(document.getElementById("map"), {
    center: astorPlace,
    zoom: 18,
    streetViewControl: false,
  });

  document.getElementById("toggle").addEventListener("click", toggleStreetView);

  // Set up the markers on the map
  const cafeMarker = new google.maps.Marker({
    position: { lat: 40.730031, lng: -73.991428 },
    map,
    icon: "https://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=cafe|FFFF00",
    title: "Cafe",
  });
  const bankMarker = new google.maps.Marker({
    position: { lat: 40.729681, lng: -73.991138 },
    map,
    icon: "https://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=dollar|FFFF00",
    title: "Bank",
  });
  const busMarker = new google.maps.Marker({
    position: { lat: 40.729559, lng: -73.990741 },
    map,
    icon: "https://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=bus|FFFF00",
    title: "Bus Stop",
  });

  // We get the map's default panorama and set up some defaults.
  // Note that we don't yet set it visible.
  panorama = map.getStreetView(); // TODO fix type
  panorama.setPosition(astorPlace);
  panorama.setPov(
    /** @type {google.maps.StreetViewPov} */ {
      heading: 265,
      pitch: 0,
    },
  );
}

function toggleStreetView() {
  const toggle = panorama.getVisible();

  if (toggle == false) {
    panorama.setVisible(true);
  } else {
    panorama.setVisible(false);
  }
}

window.initMap = initMap;

CSS

/* 
 * Always set the map height explicitly to define the size of the div element
 * that contains the map. 
 */
#map {
  height: 100%;
}

/* 
 * Optional: Makes the sample page fill the window. 
 */
html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}

#floating-panel {
  position: absolute;
  top: 10px;
  left: 25%;
  z-index: 5;
  background-color: #fff;
  padding: 5px;
  border: 1px solid #999;
  text-align: center;
  font-family: "Roboto", "sans-serif";
  line-height: 30px;
  padding-left: 10px;
}

#floating-panel {
  margin-left: -100px;
}

एचटीएमएल

<html>
  <head>
    <title>Overlays Within Street View</title>
    <script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>

    <link rel="stylesheet" type="text/css" href="./style.css" />
    <script type="module" src="./index.js"></script>
  </head>
  <body>
    <div id="floating-panel">
      <input type="button" value="Toggle Street View" id="toggle" />
    </div>
    <div id="map"></div>

    <!-- 
      The `defer` attribute causes the callback to execute after the full HTML
      document has been parsed. For non-blocking uses, avoiding race conditions,
      and consistent behavior across browsers, consider loading using Promises.
      See https://developers.google.com/maps/documentation/javascript/load-maps-js-api
      for more information.
      -->
    <script
      src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg&callback=initMap&v=weekly"
      defer
    ></script>
  </body>
</html>
उदाहरण देखें

सैंपल आज़माएं

Street View इवेंट

Street View की स्क्रीन पर नेविगेट करते समय या उसके ओरिएंटेशन में बदलाव करते समय, ऐसा हो सकता है कि आप कई ऐसे इवेंट पर नज़र रखना चाहें जिनमें StreetViewPanorama की स्थिति में हुए बदलावों के बारे में बताया गया हो:

  • व्यक्तिगत पैनो आईडी बदलने पर, pano_changed सक्रिय हो जाता है. यह इवेंट इस बात की गारंटी नहीं देता कि पैनोरामा में मौजूद किसी भी डेटा (जैसे कि लिंक) को भी इस इवेंट के ट्रिगर होने तक बदल दिया गया है. इस इवेंट से सिर्फ़ यह पता चलता है कि पैनो आईडी बदल गया है. ध्यान दें कि पैनोरामा आईडी (इस पैनोरामा का रेफ़रंस देने के लिए, इसका इस्तेमाल किया जा सकता है) सिर्फ़ मौजूदा ब्राउज़र सेशन में ही स्थिर रहता है.
  • पैनोरामा की मौजूदा स्थिति (LatLng) बदलने पर, position_changed सक्रिय हो जाता है. पैनोरामा घुमाने से इस इवेंट को ट्रिगर नहीं किया जाएगा. ध्यान दें कि आप पाए गए पैनो आईडी को बदले बिना, पैनोरामा के मौजूदा स्थान को बदल सकते हैं, क्योंकि एपीआई पैनोरामा के स्थान से अपने आप सबसे नज़दीकी पैनो आईडी जोड़ देगा.
  • जब भी Street View का StreetViewPov बदलता है, तब pov_changed सक्रिय होता है. ध्यान दें कि इस इवेंट से पेज की पोज़िशन और पैनो आईडी में कोई बदलाव नहीं हो सकता.
  • 'स्ट्रीट व्यू' के लिंक बदलने पर, links_changed सक्रिय हो जाता है. ध्यान दें कि यह इवेंट pano_changed के ज़रिए दिखाए गए पैनो आईडी में बदलाव के बाद, एसिंक्रोनस तरीके से चालू हो सकता है.
  • जब भी Street View के दिखने की सेटिंग बदलती है, तब visible_changed सक्रिय होता है. ध्यान दें कि यह इवेंट pano_changed के ज़रिए दिखाए गए पैनो आईडी में बदलाव के बाद, एसिंक्रोनस तरीके से चालू हो सकता है.

इस कोड में बताया गया है कि StreetViewPanorama में मौजूद डेटा को इकट्ठा करने के लिए, इन इवेंट को कैसे मैनेज किया जा सकता है:

TypeScript

function initPano() {
  const panorama = new google.maps.StreetViewPanorama(
    document.getElementById("pano") as HTMLElement,
    {
      position: { lat: 37.869, lng: -122.255 },
      pov: {
        heading: 270,
        pitch: 0,
      },
      visible: true,
    }
  );

  panorama.addListener("pano_changed", () => {
    const panoCell = document.getElementById("pano-cell") as HTMLElement;

    panoCell.innerHTML = panorama.getPano();
  });

  panorama.addListener("links_changed", () => {
    const linksTable = document.getElementById("links_table") as HTMLElement;

    while (linksTable.hasChildNodes()) {
      linksTable.removeChild(linksTable.lastChild as ChildNode);
    }

    const links = panorama.getLinks();

    for (const i in links) {
      const row = document.createElement("tr");

      linksTable.appendChild(row);

      const labelCell = document.createElement("td");

      labelCell.innerHTML = "<b>Link: " + i + "</b>";

      const valueCell = document.createElement("td");

      valueCell.innerHTML = links[i].description as string;
      linksTable.appendChild(labelCell);
      linksTable.appendChild(valueCell);
    }
  });

  panorama.addListener("position_changed", () => {
    const positionCell = document.getElementById(
      "position-cell"
    ) as HTMLElement;

    (positionCell.firstChild as HTMLElement).nodeValue =
      panorama.getPosition() + "";
  });

  panorama.addListener("pov_changed", () => {
    const headingCell = document.getElementById("heading-cell") as HTMLElement;
    const pitchCell = document.getElementById("pitch-cell") as HTMLElement;

    (headingCell.firstChild as HTMLElement).nodeValue =
      panorama.getPov().heading + "";
    (pitchCell.firstChild as HTMLElement).nodeValue =
      panorama.getPov().pitch + "";
  });
}

declare global {
  interface Window {
    initPano: () => void;
  }
}
window.initPano = initPano;

JavaScript

function initPano() {
  const panorama = new google.maps.StreetViewPanorama(
    document.getElementById("pano"),
    {
      position: { lat: 37.869, lng: -122.255 },
      pov: {
        heading: 270,
        pitch: 0,
      },
      visible: true,
    },
  );

  panorama.addListener("pano_changed", () => {
    const panoCell = document.getElementById("pano-cell");

    panoCell.innerHTML = panorama.getPano();
  });
  panorama.addListener("links_changed", () => {
    const linksTable = document.getElementById("links_table");

    while (linksTable.hasChildNodes()) {
      linksTable.removeChild(linksTable.lastChild);
    }

    const links = panorama.getLinks();

    for (const i in links) {
      const row = document.createElement("tr");

      linksTable.appendChild(row);

      const labelCell = document.createElement("td");

      labelCell.innerHTML = "<b>Link: " + i + "</b>";

      const valueCell = document.createElement("td");

      valueCell.innerHTML = links[i].description;
      linksTable.appendChild(labelCell);
      linksTable.appendChild(valueCell);
    }
  });
  panorama.addListener("position_changed", () => {
    const positionCell = document.getElementById("position-cell");

    positionCell.firstChild.nodeValue = panorama.getPosition() + "";
  });
  panorama.addListener("pov_changed", () => {
    const headingCell = document.getElementById("heading-cell");
    const pitchCell = document.getElementById("pitch-cell");

    headingCell.firstChild.nodeValue = panorama.getPov().heading + "";
    pitchCell.firstChild.nodeValue = panorama.getPov().pitch + "";
  });
}

window.initPano = initPano;

CSS

/* 
 * Always set the map height explicitly to define the size of the div element
 * that contains the map. 
 */
#map {
  height: 100%;
}

/* 
 * Optional: Makes the sample page fill the window. 
 */
html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}

#floating-panel {
  position: absolute;
  top: 10px;
  left: 25%;
  z-index: 5;
  background-color: #fff;
  padding: 5px;
  border: 1px solid #999;
  text-align: center;
  font-family: "Roboto", "sans-serif";
  line-height: 30px;
  padding-left: 10px;
}

#pano {
  width: 50%;
  height: 100%;
  float: left;
}

#floating-panel {
  width: 45%;
  height: 100%;
  float: right;
  text-align: left;
  overflow: auto;
  position: static;
  border: 0px solid #999;
}

एचटीएमएल

<html>
  <head>
    <title>Street View Events</title>
    <script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>

    <link rel="stylesheet" type="text/css" href="./style.css" />
    <script type="module" src="./index.js"></script>
  </head>
  <body>
    <div id="pano"></div>
    <div id="floating-panel">
      <table>
        <tr>
          <td><b>Position</b></td>
          <td id="position-cell">&nbsp;</td>
        </tr>
        <tr>
          <td><b>POV Heading</b></td>
          <td id="heading-cell">270</td>
        </tr>
        <tr>
          <td><b>POV Pitch</b></td>
          <td id="pitch-cell">0.0</td>
        </tr>
        <tr>
          <td><b>Pano ID</b></td>
          <td id="pano-cell">&nbsp;</td>
        </tr>
        <table id="links_table"></table>
      </table>
    </div>

    <!-- 
      The `defer` attribute causes the callback to execute after the full HTML
      document has been parsed. For non-blocking uses, avoiding race conditions,
      and consistent behavior across browsers, consider loading using Promises.
      See https://developers.google.com/maps/documentation/javascript/load-maps-js-api
      for more information.
      -->
    <script
      src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg&callback=initPano&v=weekly"
      defer
    ></script>
  </body>
</html>
उदाहरण देखें

सैंपल आज़माएं

स्ट्रीट व्यू कंट्रोल

StreetViewPanorama दिखाते समय, डिफ़ॉल्ट रूप से पैनोरामा में कई तरह के कंट्रोल दिखते हैं. StreetViewPanoramaOptions में सही फ़ील्ड सेट करके, true या false पर इन कंट्रोल को चालू या बंद किया जा सकता है.

  • panControl, पैनोरामा को घुमाने का तरीका बताता है. यह कंट्रोल, डिफ़ॉल्ट रूप से स्टैंडर्ड इंटिग्रेट किए गए कंपास और पैन कंट्रोल के तौर पर दिखता है. panControlOptions फ़ील्ड में PanControlOptions देकर, कंट्रोल की जगह बदली जा सकती है.
  • zoomControl की मदद से, इमेज में ज़ूम इन किया जा सकता है. यह कंट्रोल पैनोरामा के सबसे नीचे दाईं ओर डिफ़ॉल्ट रूप से दिखता है. zoomControlOptions फ़ील्ड में ZoomControlOptions देकर, कंट्रोल के दिखने का तरीका बदला जा सकता है.
  • addressControl टेक्स्ट के साथ एक ओवरले उपलब्ध कराता है, जिसमें संबंधित जगह का पता दिया जाता है. साथ ही, उस लिंक की मदद से Google Maps पर उस जगह को खोला जा सकता है. addressControlOptions फ़ील्ड में StreetViewAddressControlOptions देकर, कंट्रोल के दिखने का तरीका बदला जा सकता है.
  • fullscreenControl, Street View को फ़ुलस्क्रीन मोड में खोलने का विकल्प देता है. fullscreenControlOptions फ़ील्ड में FullscreenControlOptions देकर, कंट्रोल के दिखने का तरीका बदला जा सकता है.
  • motionTrackingControl से मोबाइल डिवाइस पर मोशन ट्रैकिंग की सुविधा चालू या बंद करने का विकल्प मिलता है. यह कंट्रोल सिर्फ़ उन डिवाइसों पर दिखता है जिन पर डिवाइस ओरिएंटेशन इवेंट काम करते हैं. डिफ़ॉल्ट रूप से, कंट्रोल पैनोरामा के सबसे नीचे दाईं ओर दिखता है. MotionTrackingControlOptions देकर, कंट्रोल की जगह बदली जा सकती है. ज़्यादा जानकारी के लिए, मोशन ट्रैकिंग का सेक्शन देखें.
  • linksControl, इमेज के बारे में गाइड के साथ ऐरो दिखाता है. इससे, इमेज के एक-दूसरे के पास पहुंचने में मदद मिलती है.
  • बंद करने का कंट्रोल, उपयोगकर्ता को Street View व्यूअर बंद करने की अनुमति देता है. enableCloseButton को true या false पर सेट करके, बंद करने के कंट्रोल को चालू या बंद किया जा सकता है.

नीचे दिया गया उदाहरण, 'स्ट्रीट व्यू' में दिखने वाले कंट्रोल को बदल देता है और व्यू के लिंक को हटा देता है:

TypeScript

function initPano() {
  // Note: constructed panorama objects have visible: true
  // set by default.
  const panorama = new google.maps.StreetViewPanorama(
    document.getElementById("map") as HTMLElement,
    {
      position: { lat: 42.345573, lng: -71.098326 },
      addressControlOptions: {
        position: google.maps.ControlPosition.BOTTOM_CENTER,
      },
      linksControl: false,
      panControl: false,
      enableCloseButton: false,
    }
  );
}

declare global {
  interface Window {
    initPano: () => void;
  }
}
window.initPano = initPano;

JavaScript

function initPano() {
  // Note: constructed panorama objects have visible: true
  // set by default.
  const panorama = new google.maps.StreetViewPanorama(
    document.getElementById("map"),
    {
      position: { lat: 42.345573, lng: -71.098326 },
      addressControlOptions: {
        position: google.maps.ControlPosition.BOTTOM_CENTER,
      },
      linksControl: false,
      panControl: false,
      enableCloseButton: false,
    },
  );
}

window.initPano = initPano;

CSS

/* 
 * Always set the map height explicitly to define the size of the div element
 * that contains the map. 
 */
#map {
  height: 100%;
}

/* 
 * Optional: Makes the sample page fill the window. 
 */
html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}

एचटीएमएल

<html>
  <head>
    <title>Street View Controls</title>
    <script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>

    <link rel="stylesheet" type="text/css" href="./style.css" />
    <script type="module" src="./index.js"></script>
  </head>
  <body>
    <div id="map"></div>

    <!-- 
      The `defer` attribute causes the callback to execute after the full HTML
      document has been parsed. For non-blocking uses, avoiding race conditions,
      and consistent behavior across browsers, consider loading using Promises.
      See https://developers.google.com/maps/documentation/javascript/load-maps-js-api
      for more information.
      -->
    <script
      src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg&callback=initPano&v=weekly"
      defer
    ></script>
  </body>
</html>
उदाहरण देखें

सैंपल आज़माएं

Street View डेटा को सीधे तौर पर ऐक्सेस करना

आप मैप या पैनोरामा में बदलाव किए बिना, Street View डेटा की उपलब्धता को प्रोग्राम के हिसाब से तय कर सकते हैं या किसी खास पैनोरामा के बारे में जानकारी दिखा सकते हैं. StreetViewService ऑब्जेक्ट का इस्तेमाल करके, ऐसा किया जा सकता है. इससे, Google की Street View सेवा में सेव किए गए डेटा का इंटरफ़ेस मिलता है.

Street View सेवा के अनुरोध

Street View सेवा ऐक्सेस नहीं की जा सकती, क्योंकि इसके लिए Google Maps API को किसी बाहरी सर्वर को कॉल करना होता है. इस वजह से, आपको अनुरोध पूरा होने पर कॉलबैक तरीका इस्तेमाल करना होगा. कॉलबैक का यह तरीका, नतीजे को प्रोसेस करता है.

आप StreetViewPanoRequest या StreetViewLocationRequest का इस्तेमाल करके, StreetViewService को अनुरोध भेज सकते हैं.

StreetViewPanoRequest का इस्तेमाल करने वाले अनुरोध से, पैनोरामा का डेटा दिखता है. यह रेफ़रंस आईडी, खास तौर पर पैनोरामा की पहचान करता है. ध्यान दें कि ये रेफ़रंस आईडी सिर्फ़ उस पैनोरामा के लाइफ़टाइम के लिए स्थायी होते हैं जो इस पैनोरामा में मौजूद है.

StreetViewLocationRequest का इस्तेमाल करके, नीचे दिए गए पैरामीटर का इस्तेमाल करके, किसी खास जगह पर पैनोरामा डेटा खोजने का अनुरोध किया जाता है:

  • पैनोरामा खोजने के लिए, location से अक्षांश और देशांतर की जानकारी मिलती है.
  • preference के लिए एक प्राथमिकता सेट की जाती है कि किस दायरे में कौनसा दायरा दिखना चाहिए: दिया गया जगह का सबसे नज़दीकी व्यू या खास दायरा.
  • radius में एक दायरा सेट किया जाता है, जो मीटर में दिया गया होता है. इसमें, दिए गए अक्षांश और देशांतर के आधार पर, पैनोरामा खोजा जाता है. न दिए जाने पर डिफ़ॉल्ट तौर पर 50 होता है.
  • source, पैनोरामा खोजने का स्रोत बताता है. ये मान्य वैल्यू हैं:
    • default, स्ट्रीट व्यू के लिए डिफ़ॉल्ट सोर्स का इस्तेमाल करता है; खोज सिर्फ़ खास सोर्स तक सीमित नहीं होती हैं.
    • outdoor, आउटडोर कलेक्शन के लिए की जाने वाली खोजों को सीमित करता है. ध्यान दें कि किसी खास जगह के लिए आउटडोर पैनोरामा शायद मौजूद न हों.

Street View सेवा से जुड़े जवाब

getPanorama() फ़ंक्शन को Street View सेवा से नतीजे वापस पाने के लिए, कॉलबैक फ़ंक्शन की ज़रूरत होती है. यह कॉलबैक फ़ंक्शन, StreetViewPanoramaData ऑब्जेक्ट में पैनोरामा डेटा का एक सेट दिखाता है. साथ ही, यह अनुरोध की स्थिति को दिखाने वाला StreetViewStatus कोड उसी क्रम में दिखाता है.

StreetViewPanoramaData ऑब्जेक्ट की खास बातों में, इस फ़ॉर्म के Street View पैनोरामा का मेटा-डेटा शामिल होता है:

{
  "location": {
    "latLng": LatLng,
    "description": string,
    "pano": string
  },
  "copyright": string,
  "links": [{
      "heading": number,
      "description": string,
      "pano": string,
      "roadColor": string,
      "roadOpacity": number
    }],
  "tiles": {
    "worldSize": Size,
    "tileSize": Size,
    "centerHeading": number
  }
}

ध्यान दें कि यह डेटा ऑब्जेक्ट, खुद StreetViewPanorama ऑब्जेक्ट नहीं है. इस डेटा का इस्तेमाल करके, 'स्ट्रीट व्यू' ऑब्जेक्ट बनाने के लिए, आपको एक StreetViewPanorama बनाना होगा. साथ ही, setPano() को कॉल करना होगा और आईडी को 'लौटाए गए' location.pano फ़ील्ड में डालना होगा.

status कोड इनमें से कोई एक वैल्यू दिखा सकता है:

  • OK से यह पता चलता है कि इस सेवा से मिलता-जुलता पैनोरामा मिला है.
  • ZERO_RESULTS से पता चलता है कि इस सेवा को पास की गई शर्तों से मिलता-जुलता कोई पैनोरामा नहीं मिला.
  • UNKNOWN_ERROR यह बताता है कि Street View के अनुरोध को प्रोसेस नहीं किया जा सका. हालांकि, इसकी सही वजह पता नहीं है.

यह कोड एक StreetViewService बनाता है, जो मैप पर उपयोगकर्ता के क्लिक का जवाब देता है. इन मार्कर को क्लिक करने पर, उस जगह का StreetViewPanorama दिखाया जाता है. यह कोड, सेवा का इस्तेमाल करके दिए गए StreetViewPanoramaData के कॉन्टेंट का इस्तेमाल करता है.

TypeScript

/*
 * Click the map to set a new location for the Street View camera.
 */

let map: google.maps.Map;

let panorama: google.maps.StreetViewPanorama;

function initMap(): void {
  const berkeley = { lat: 37.869085, lng: -122.254775 };
  const sv = new google.maps.StreetViewService();

  panorama = new google.maps.StreetViewPanorama(
    document.getElementById("pano") as HTMLElement
  );

  // Set up the map.
  map = new google.maps.Map(document.getElementById("map") as HTMLElement, {
    center: berkeley,
    zoom: 16,
    streetViewControl: false,
  });

  // Set the initial Street View camera to the center of the map
  sv.getPanorama({ location: berkeley, radius: 50 }).then(processSVData);

  // Look for a nearby Street View panorama when the map is clicked.
  // getPanorama will return the nearest pano when the given
  // radius is 50 meters or less.
  map.addListener("click", (event) => {
    sv.getPanorama({ location: event.latLng, radius: 50 })
      .then(processSVData)
      .catch((e) =>
        console.error("Street View data not found for this location.")
      );
  });
}

function processSVData({ data }: google.maps.StreetViewResponse) {
  const location = data.location!;

  const marker = new google.maps.Marker({
    position: location.latLng,
    map,
    title: location.description,
  });

  panorama.setPano(location.pano as string);
  panorama.setPov({
    heading: 270,
    pitch: 0,
  });
  panorama.setVisible(true);

  marker.addListener("click", () => {
    const markerPanoID = location.pano;

    // Set the Pano to use the passed panoID.
    panorama.setPano(markerPanoID as string);
    panorama.setPov({
      heading: 270,
      pitch: 0,
    });
    panorama.setVisible(true);
  });
}

declare global {
  interface Window {
    initMap: () => void;
  }
}
window.initMap = initMap;

JavaScript

/*
 * Click the map to set a new location for the Street View camera.
 */
let map;
let panorama;

function initMap() {
  const berkeley = { lat: 37.869085, lng: -122.254775 };
  const sv = new google.maps.StreetViewService();

  panorama = new google.maps.StreetViewPanorama(
    document.getElementById("pano"),
  );
  // Set up the map.
  map = new google.maps.Map(document.getElementById("map"), {
    center: berkeley,
    zoom: 16,
    streetViewControl: false,
  });
  // Set the initial Street View camera to the center of the map
  sv.getPanorama({ location: berkeley, radius: 50 }).then(processSVData);
  // Look for a nearby Street View panorama when the map is clicked.
  // getPanorama will return the nearest pano when the given
  // radius is 50 meters or less.
  map.addListener("click", (event) => {
    sv.getPanorama({ location: event.latLng, radius: 50 })
      .then(processSVData)
      .catch((e) =>
        console.error("Street View data not found for this location."),
      );
  });
}

function processSVData({ data }) {
  const location = data.location;
  const marker = new google.maps.Marker({
    position: location.latLng,
    map,
    title: location.description,
  });

  panorama.setPano(location.pano);
  panorama.setPov({
    heading: 270,
    pitch: 0,
  });
  panorama.setVisible(true);
  marker.addListener("click", () => {
    const markerPanoID = location.pano;

    // Set the Pano to use the passed panoID.
    panorama.setPano(markerPanoID);
    panorama.setPov({
      heading: 270,
      pitch: 0,
    });
    panorama.setVisible(true);
  });
}

window.initMap = initMap;

CSS

/* 
 * Always set the map height explicitly to define the size of the div element
 * that contains the map. 
 */
#map {
  height: 100%;
}

/* 
 * Optional: Makes the sample page fill the window. 
 */
html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}

एचटीएमएल

<html>
  <head>
    <title>Directly Accessing Street View Data</title>
    <script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>

    <link rel="stylesheet" type="text/css" href="./style.css" />
    <script type="module" src="./index.js"></script>
  </head>
  <body>
    <div id="map" style="width: 45%; height: 100%; float: left"></div>
    <div id="pano" style="width: 45%; height: 100%; float: left"></div>

    <!-- 
      The `defer` attribute causes the callback to execute after the full HTML
      document has been parsed. For non-blocking uses, avoiding race conditions,
      and consistent behavior across browsers, consider loading using Promises.
      See https://developers.google.com/maps/documentation/javascript/load-maps-js-api
      for more information.
      -->
    <script
      src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg&callback=initMap&v=weekly"
      defer
    ></script>
  </body>
</html>
उदाहरण देखें

सैंपल आज़माएं

कस्टम Street View पैनोरामा उपलब्ध कराना

Maps JavaScript API, StreetViewPanorama ऑब्जेक्ट में कस्टम पैनोरामा दिखाने की सुविधा देता है. कस्टम पैनोरामा का इस्तेमाल करके, इमारतों के अंदर की ओर, सुंदर जगहों के नज़ारे या अपनी कल्पना से कुछ भी दिखाया जा सकता है. इन कस्टम पैनोरामा को Google के मौजूदा पैनोरामा में भी जोड़ा जा सकता है.

अपनी पसंद के मुताबिक पैनोरामा सेट अप करने के लिए यह तरीका अपनाएं:

  • हर कस्टम पैनोरामा के लिए एक बेस पैनोरामा इमेज बनाएं. यह बेस इमेज, सबसे ज़्यादा रिज़ॉल्यूशन वाली इमेज में होनी चाहिए. साथ ही, इमेज को ज़ूम इन करके दिखाना है.
  • (ज़रूरी नहीं, लेकिन सुझाया गया) बुनियादी इमेज से अलग-अलग ज़ूम लेवल पर पैनोरामा टाइल का सेट बनाएं.
  • अपने कस्टम पैनोरामा के बीच लिंक बनाएं.
  • (ज़रूरी नहीं) Google की मौजूदा 'स्ट्रीट व्यू' की तस्वीरों में दिखने वाले "एंट्री" पैनोरामा तय करें. साथ ही, कस्टम सेट से लेकर स्टैंडर्ड सेट तक या इससे लिंक को पसंद के मुताबिक बनाएं.
  • StreetViewPanoramaData ऑब्जेक्ट में, हर पैनोरामा इमेज के लिए मेटाडेटा तय करें.
  • एक तरीका लागू करें जो कस्टम पैनोरामा डेटा और इमेज को तय करता है. साथ ही, उस तरीके को StreetViewPanorama ऑब्जेक्ट में अपने कस्टम हैंडलर के रूप में तय करें.

इस सेक्शन में, इस प्रोसेस के बारे में बताया गया है.

पसंद के मुताबिक पैनोरामा बनाना

हर Street View पैनोरामा में, एक ही जगह से पूरी तरह से 360 डिग्री व्यू दिखाने वाली इमेज या इमेज सेट शामिल होते हैं. StreetViewPanorama ऑब्जेक्ट, उन इमेज का इस्तेमाल करता है जो इक्विरेक्टैंग्यूलर (प्लेट कैरी) प्रोजेक्शन के मुताबिक हैं. इस तरह के प्रोजेक्शन में, 360 डिग्री हॉरिज़ॉन्टल व्यू (पूरी तरह से रैप किया गया) और 180 डिग्री वर्टिकल व्यू शामिल होता है (सीधे ऊपर से सीधे नीचे). व्यू के ये फ़ील्ड, 2:1 के आसपेक्ट रेशियो (लंबाई-चौड़ाई का अनुपात) वाली इमेज में शामिल होते हैं. आस-पास पूरी जानकारी देने वाला पैनोरामा नीचे दिखाया गया है.

शहर की सड़क का खूबसूरत नज़ारा

आम तौर पर, पैनोरामा इमेज पाने के लिए एक ही जगह से कई फ़ोटो खींचने और पैनोरामा सॉफ़्टवेयर का इस्तेमाल करके, उन्हें एक साथ स्टिच करना होता है. (ज़्यादा जानकारी के लिए, Wikipedia के फ़ोटो स्टिचिंग ऐप्लिकेशन की तुलना देखें.) ऐसी इमेज में एक "कैमरा" स्थान होना चाहिए जिससे हर पैनोरामा इमेज ली जा रही हो. इसके बाद, 360 डिग्री का पैनोरामा उस इमेज पर गोल आकार का प्रोजेक्शन तय कर सकता है जिसे इमेज के दो डाइमेंशन वाले प्लैटफ़ॉर्म पर रैप किया गया है.

एक ऐसा मैदान जिसके सामने की सड़क पर पैनोरामा दिखता है

इमेज को आयोजक के टाइल से अलग करने और कंप्यूट टाइल के निर्देशांकों के हिसाब से इमेज दिखाने पर, फ़ायदेमंद होता है. इसके लिए, आस-पास मौजूद कोऑर्डिनेट सिस्टम की मदद से पैनोरामा का इस्तेमाल किया जाता है.

पसंद के मुताबिक पैनोरामा टाइलें बनाना

'स्ट्रीट व्यू' में ज़ूम कंट्रोल का इस्तेमाल करके, इमेज की अलग-अलग जानकारी भी दिखाई जाती है. इसकी मदद से आप डिफ़ॉल्ट व्यू से ज़ूम इन और ज़ूम आउट कर सकते हैं. आम तौर पर, किसी भी पैनोरामा इमेज के लिए Street View पांच लेवल का ज़ूम रिज़ॉल्यूशन देता है. अगर आपको सभी ज़ूम लेवल दिखाने के लिए किसी एक पैनोरामा इमेज पर भरोसा करना था, तो यह ज़रूरी है कि वह इमेज आपके ऐप्लिकेशन की साइज़ से काफ़ी बड़ी हो या उसे धीमी कर देती है. इसके अलावा, यह भी हो सकता है कि वह इमेज ज़्यादा ज़ूम लेवल पर खराब रिज़ॉल्यूशन की हो. हालांकि, अच्छी बात यह है कि हम मिलते-जुलते डिज़ाइन पैटर्न का इस्तेमाल कर सकते हैं. इस पैटर्न का इस्तेमाल अलग-अलग ज़ूम लेवल पर Google की मैप टाइल को दिखाने के लिए किया जाता है. इसकी मदद से, हर ज़ूम लेवल पर पैनोरामा के लिए सही रिज़ॉल्यूशन वाली तस्वीरें उपलब्ध कराई जा सकती हैं.

जब StreetViewPanorama पहली बार लोड होता है, तो यह डिफ़ॉल्ट रूप से ज़ूम लेवल 1 पर पैनोरामा की 25% (90 डिग्री आर्क) की इमेज दिखाता है. यह व्यू आम तौर पर एक सामान्य मानव फ़ील्ड से मिलता है. इस डिफ़ॉल्ट व्यू से "आउट" ज़ूम करने पर एक बड़ा आर्क बनता है, जबकि ज़ूम इन करने से व्यू का फ़ील्ड छोटा आर्क बन जाता है. StreetViewPanorama, चुने गए ज़ूम लेवल के लिए व्यू के सही फ़ील्ड को अपने-आप कैलकुलेट करता है. इसके बाद, उस रिज़ॉल्यूशन के लिए सबसे सही इमेज चुनता है, जो व्यू के हॉरिज़ॉन्टल फ़ील्ड के डाइमेंशन से मिलता-जुलता है. Street View ज़ूम लेवल के मैप के ये फ़ील्ड, मैप करते हैं:

स्ट्रीट व्यू ज़ूम स्तर फ़ील्ड ऑफ़ व्यू (डिग्री)
0 180
1 (डिफ़ॉल्ट) 90
2 45
3 22.5
4 11.25 साल

ध्यान दें कि Street View में दिखाई गई इमेज का साइज़, पूरी तरह से Street View कंटेनर के स्क्रीन के साइज़ (चौड़ाई) पर निर्भर करता है. अगर आपने कोई बड़ा कंटेनर दिया है, तो भी सेवा में किसी भी ज़ूम लेवल के लिए उसी फ़ील्ड को देखा जा सकता है. हालांकि, यह उस रिज़ॉल्यूशन के लिए ज़्यादा सही टाइल चुन सकता है.

हर पैनोरामा में इक्विरेक्टैंग्यूलर (इक्विरेक्टैंग्यूलर) प्रोजेक्शन होता है. इसलिए, पैनोरामा टाइलें बनाना काफ़ी आसान होता है. प्रोजेक्ट करने की सुविधा 2:1 के आसपेक्ट रेशियो (लंबाई-चौड़ाई का अनुपात) वाली इमेज उपलब्ध कराती है. वहीं, 2:1 अनुपात वाली टाइल इस्तेमाल में आसान होती है. हालांकि, स्क्वेयर टाइल से, स्क्वेयर मैप पर बेहतर परफ़ॉर्मेंस मिल सकती है, क्योंकि व्यू का फ़ील्ड स्क्वेयर होगा.

2:1 टाइल के लिए, पूरे पैनोरामा को कवर करने वाली एक इमेज पूरे ज़ूम लेवल 0 पर "आस-पास की पूरी इमेज" (बेस इमेज) दिखाती है. हर ज़ूम लेवल में ज़ूम लेवल 4 zoomLevel है. (उदाहरण के लिए, ज़ूम लेवल 2 पर, पूरे पैनोरामा में 16 टाइल हैं.) ध्यान दें: Street View के टाइल का ज़ूम लेवल, सीधे तौर पर ज़ूम लेवल से मेल नहीं खाता, जैसा कि Street View के कंट्रोल का इस्तेमाल करके दिया गया है. इसके बजाय, Street View के कंट्रोल लेवल को ज़ूम करने पर, फ़ील्ड ऑफ़ व्यू (FoV) चुना जाता है, जहां से सही टाइल चुनी जाती हैं.

टाइल से शहर की सड़क का नज़ारा

आम तौर पर, अपनी इमेज टाइल को कोई नाम दें, ताकि उन्हें प्रोग्राम के हिसाब से चुना जा सके. नाम रखने के ऐसे तरीके के बारे में नीचे पसंद के मुताबिक पैनोरामा अनुरोधों को मैनेज करना में बताया गया है.

पसंद के मुताबिक पैनोरामा अनुरोधों को मैनेज करना

कस्टम पैनोरामा का इस्तेमाल करने के लिए, StreetViewPanorama.registerPanoProvider() को कॉल करें और अपने कस्टम पैनोरामा प्रोवाइडर के तरीके का नाम बताएं. पैनोरामा की सेवा देने वाले तरीके में StreetViewPanoramaData ऑब्जेक्ट दिखाना चाहिए और इसमें ये हस्ताक्षर भी होने चाहिए:

Function(pano):StreetViewPanoramaData

StreetViewPanoramaData, इस फ़ॉर्म का ऑब्जेक्ट है:

{
  copyright: string,
  location: {
    description: string,
    latLng: google.maps.LatLng,
    pano: string
  },
  tiles: {
    tileSize: google.maps.Size,
    worldSize: google.maps.Size,
    heading: number,
    getTileUrl: Function
  },
  links: [
    description: string,
    heading: number,
    pano: string,
    roadColor: string,
    roadOpacity: number
  ]
}

कस्टम पैनोरामा को इस तरह दिखाएं:

  • StreetViewPanoramaOptions.pano प्रॉपर्टी को पसंद के मुताबिक वैल्यू पर सेट करें.
  • कस्टम पैनोरामा प्रोवाइडर फ़ंक्शन के लिए StreetViewPanorama.registerPanoProvider() को कॉल करें.
  • अपनी पसंद के मुताबिक पैनोरामा की सेवा देने वाली कंपनी के फ़ंक्शन लागू करके, बताई गई pano वैल्यू का इस्तेमाल करें.
  • StreetViewPanoramaData ऑब्जेक्ट बनाएं.
  • StreetViewTileData.getTileUrl प्रॉपर्टी को, दिए गए कस्टम टाइल प्रोवाइडर के नाम पर सेट करें. उदाहरण के लिए, getCustomPanoramaTileUrl.
  • नीचे दिए गए नमूनों में दिखाए गए तरीके से, पसंद के मुताबिक टाइल देने वाली कंपनी के फ़ंक्शन को लागू करें.
  • StreetViewPanoramaData ऑब्जेक्ट दिखाएं.

ध्यान दें: अगर आप कस्टम पैनोरामा दिखाना चाहते हैं, तो StreetViewPanorama में सीधे position सेट न करें. ऐसी जगह ही 'स्ट्रीट व्यू' की सेवा को निर्देश देगी कि वह जगह के पास डिफ़ॉल्ट 'स्ट्रीट व्यू' की तस्वीरें दिखाने का अनुरोध करे. इसके बजाय, StreetViewPanoramaData पोज़िशन के location.latLng फ़ील्ड में इस पोज़िशन को सेट करें.

इस उदाहरण में, Google सिडनी ऑफ़िस का पसंद के मुताबिक बनाया गया पैनोरामा दिखाया गया है. ध्यान दें कि इस उदाहरण में मैप या डिफ़ॉल्ट 'स्ट्रीट व्यू' की तस्वीरों का इस्तेमाल नहीं किया गया है:

TypeScript

function initPano() {
  // Set up Street View and initially set it visible. Register the
  // custom panorama provider function. Set the StreetView to display
  // the custom panorama 'reception' which we check for below.
  const panorama = new google.maps.StreetViewPanorama(
    document.getElementById("map") as HTMLElement,
    { pano: "reception", visible: true }
  );

  panorama.registerPanoProvider(getCustomPanorama);
}

// Return a pano image given the panoID.
function getCustomPanoramaTileUrl(
  pano: string,
  zoom: number,
  tileX: number,
  tileY: number
): string {
  return (
    "https://developers.google.com/maps/documentation/javascript/examples/full/images/" +
    "panoReception1024-" +
    zoom +
    "-" +
    tileX +
    "-" +
    tileY +
    ".jpg"
  );
}

// Construct the appropriate StreetViewPanoramaData given
// the passed pano IDs.
function getCustomPanorama(pano: string): google.maps.StreetViewPanoramaData {
  if (pano === "reception") {
    return {
      location: {
        pano: "reception",
        description: "Google Sydney - Reception",
      },
      links: [],
      // The text for the copyright control.
      copyright: "Imagery (c) 2010 Google",
      // The definition of the tiles for this panorama.
      tiles: {
        tileSize: new google.maps.Size(1024, 512),
        worldSize: new google.maps.Size(2048, 1024),
        // The heading in degrees at the origin of the panorama
        // tile set.
        centerHeading: 105,
        getTileUrl: getCustomPanoramaTileUrl,
      },
    };
  }
  // @ts-ignore TODO fix typings
  return null;
}

declare global {
  interface Window {
    initPano: () => void;
  }
}
window.initPano = initPano;

JavaScript

function initPano() {
  // Set up Street View and initially set it visible. Register the
  // custom panorama provider function. Set the StreetView to display
  // the custom panorama 'reception' which we check for below.
  const panorama = new google.maps.StreetViewPanorama(
    document.getElementById("map"),
    { pano: "reception", visible: true },
  );

  panorama.registerPanoProvider(getCustomPanorama);
}

// Return a pano image given the panoID.
function getCustomPanoramaTileUrl(pano, zoom, tileX, tileY) {
  return (
    "https://developers.google.com/maps/documentation/javascript/examples/full/images/" +
    "panoReception1024-" +
    zoom +
    "-" +
    tileX +
    "-" +
    tileY +
    ".jpg"
  );
}

// Construct the appropriate StreetViewPanoramaData given
// the passed pano IDs.
function getCustomPanorama(pano) {
  if (pano === "reception") {
    return {
      location: {
        pano: "reception",
        description: "Google Sydney - Reception",
      },
      links: [],
      // The text for the copyright control.
      copyright: "Imagery (c) 2010 Google",
      // The definition of the tiles for this panorama.
      tiles: {
        tileSize: new google.maps.Size(1024, 512),
        worldSize: new google.maps.Size(2048, 1024),
        // The heading in degrees at the origin of the panorama
        // tile set.
        centerHeading: 105,
        getTileUrl: getCustomPanoramaTileUrl,
      },
    };
  }
  // @ts-ignore TODO fix typings
  return null;
}

window.initPano = initPano;

CSS

/* 
 * Always set the map height explicitly to define the size of the div element
 * that contains the map. 
 */
#map {
  height: 100%;
}

/* 
 * Optional: Makes the sample page fill the window. 
 */
html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}

एचटीएमएल

<html>
  <head>
    <title>Custom Street View Panoramas</title>
    <script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>

    <link rel="stylesheet" type="text/css" href="./style.css" />
    <script type="module" src="./index.js"></script>
  </head>
  <body>
    <div id="map"></div>

    <!-- 
      The `defer` attribute causes the callback to execute after the full HTML
      document has been parsed. For non-blocking uses, avoiding race conditions,
      and consistent behavior across browsers, consider loading using Promises.
      See https://developers.google.com/maps/documentation/javascript/load-maps-js-api
      for more information.
      -->
    <script
      src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg&callback=initPano&v=weekly"
      defer
    ></script>
  </body>
</html>
उदाहरण देखें

सैंपल आज़माएं

कस्टम पैनोरामा सेवा देने वाली कंपनी, पास किए गए पैनोरामा आईडी, ज़ूम लेवल, और पैनोरामा टाइल निर्देशांकों के साथ सही टाइल दिखाती है. इमेज चुनना इन पास की गई वैल्यू पर निर्भर करता है. इसलिए, जिन इमेज को पास किया जाता है उन्हें प्रोग्राम के हिसाब से चुना जा सकता है, क्योंकि उन वैल्यू को पास किया जाता है, जैसे कि pano_zoom_tileX_tileY.png.

नीचे दिए गए उदाहरण में, इमेज के लिए एक और ऐरो जोड़ा गया है. यह डिफ़ॉल्ट Street View नेविगेशन ऐरो है, जो Google सिडनी को दिखाता है और इसे पसंद के मुताबिक बनाई गई तस्वीरों के लिंक से जोड़ देता है:

TypeScript

let panorama: google.maps.StreetViewPanorama;

// StreetViewPanoramaData of a panorama just outside the Google Sydney office.
let outsideGoogle: google.maps.StreetViewPanoramaData;

// StreetViewPanoramaData for a custom panorama: the Google Sydney reception.
function getReceptionPanoramaData(): google.maps.StreetViewPanoramaData {
  return {
    location: {
      pano: "reception", // The ID for this custom panorama.
      description: "Google Sydney - Reception",
      latLng: new google.maps.LatLng(-33.86684, 151.19583),
    },
    links: [
      {
        heading: 195,
        description: "Exit",
        pano: (outsideGoogle.location as google.maps.StreetViewLocation).pano,
      },
    ],
    copyright: "Imagery (c) 2010 Google",
    tiles: {
      tileSize: new google.maps.Size(1024, 512),
      worldSize: new google.maps.Size(2048, 1024),
      centerHeading: 105,
      getTileUrl: function (
        pano: string,
        zoom: number,
        tileX: number,
        tileY: number
      ): string {
        return (
          "https://developers.google.com/maps/documentation/javascript/examples/full/images/" +
          "panoReception1024-" +
          zoom +
          "-" +
          tileX +
          "-" +
          tileY +
          ".jpg"
        );
      },
    },
  };
}

function initPanorama() {
  panorama = new google.maps.StreetViewPanorama(
    document.getElementById("street-view") as HTMLElement,
    { pano: (outsideGoogle.location as google.maps.StreetViewLocation).pano }
  );
  // Register a provider for the custom panorama.
  panorama.registerPanoProvider(
    (pano: string): google.maps.StreetViewPanoramaData => {
      if (pano === "reception") {
        return getReceptionPanoramaData();
      }
      // @ts-ignore TODO fix typings
      return null;
    }
  );

  // Add a link to our custom panorama from outside the Google Sydney office.
  panorama.addListener("links_changed", () => {
    if (
      panorama.getPano() ===
      (outsideGoogle.location as google.maps.StreetViewLocation).pano
    ) {
      panorama.getLinks().push({
        description: "Google Sydney",
        heading: 25,
        pano: "reception",
      });
    }
  });
}

function initMap(): void {
  // Use the Street View service to find a pano ID on Pirrama Rd, outside the
  // Google office.
  new google.maps.StreetViewService()
    .getPanorama({ location: { lat: -33.867386, lng: 151.195767 } })
    .then(({ data }: google.maps.StreetViewResponse) => {
      outsideGoogle = data;
      initPanorama();
    });
}

declare global {
  interface Window {
    initMap: () => void;
  }
}
window.initMap = initMap;

JavaScript

let panorama;
// StreetViewPanoramaData of a panorama just outside the Google Sydney office.
let outsideGoogle;

// StreetViewPanoramaData for a custom panorama: the Google Sydney reception.
function getReceptionPanoramaData() {
  return {
    location: {
      pano: "reception",
      description: "Google Sydney - Reception",
      latLng: new google.maps.LatLng(-33.86684, 151.19583),
    },
    links: [
      {
        heading: 195,
        description: "Exit",
        pano: outsideGoogle.location.pano,
      },
    ],
    copyright: "Imagery (c) 2010 Google",
    tiles: {
      tileSize: new google.maps.Size(1024, 512),
      worldSize: new google.maps.Size(2048, 1024),
      centerHeading: 105,
      getTileUrl: function (pano, zoom, tileX, tileY) {
        return (
          "https://developers.google.com/maps/documentation/javascript/examples/full/images/" +
          "panoReception1024-" +
          zoom +
          "-" +
          tileX +
          "-" +
          tileY +
          ".jpg"
        );
      },
    },
  };
}

function initPanorama() {
  panorama = new google.maps.StreetViewPanorama(
    document.getElementById("street-view"),
    { pano: outsideGoogle.location.pano },
  );
  // Register a provider for the custom panorama.
  panorama.registerPanoProvider((pano) => {
    if (pano === "reception") {
      return getReceptionPanoramaData();
    }
    // @ts-ignore TODO fix typings
    return null;
  });
  // Add a link to our custom panorama from outside the Google Sydney office.
  panorama.addListener("links_changed", () => {
    if (panorama.getPano() === outsideGoogle.location.pano) {
      panorama.getLinks().push({
        description: "Google Sydney",
        heading: 25,
        pano: "reception",
      });
    }
  });
}

function initMap() {
  // Use the Street View service to find a pano ID on Pirrama Rd, outside the
  // Google office.
  new google.maps.StreetViewService()
    .getPanorama({ location: { lat: -33.867386, lng: 151.195767 } })
    .then(({ data }) => {
      outsideGoogle = data;
      initPanorama();
    });
}

window.initMap = initMap;

CSS

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}

#street-view {
  height: 100%;
}

एचटीएमएल

<html>
  <head>
    <title>Custom Street View Panorama Tiles</title>
    <script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>

    <link rel="stylesheet" type="text/css" href="./style.css" />
    <script type="module" src="./index.js"></script>
  </head>
  <body>
    <div id="street-view"></div>

    <!-- 
      The `defer` attribute causes the callback to execute after the full HTML
      document has been parsed. For non-blocking uses, avoiding race conditions,
      and consistent behavior across browsers, consider loading using Promises.
      See https://developers.google.com/maps/documentation/javascript/load-maps-js-api
      for more information.
      -->
    <script
      src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg&callback=initMap&v=weekly"
      defer
    ></script>
  </body>
</html>
उदाहरण देखें

सैंपल आज़माएं