के अंदर एक Google मानचित्र सड़क दृश्य का पुन: उपयोग करें मैं रेल में एक वेब ऐप विकसित कर रहा हूं। जब मैं मार्कर खोलता हूं, तो बॉक्स में एक सड़क दृश्य के साथ एक मॉडल पॉप-अप होता है। मैं एक या दो मार्कर खोल सकता हूं, लेकिन इसके बाद मुझे एक त्रुटि मिलती है कि वेबजीएल ने एक झटके मारा है। मैंने संसाधनों के लिए ऑनलाइन देखने की कोशिश की है लेकिन कुछ भी समझ में नहीं आता है। अधिक जानकारी के लिए चित्रों के नीचे देखें। किसी भी तरह की सहायता का स्वागत किया जाएगा।एक मॉडेल
यहाँ मेरी webapp में मेरी जावास्क्रिप्ट कोड है:
यहाँ मेरी सांत्वना लॉग कैसा दिखता है की एक छवि है।
<script type="text/javascript">
var handler = Gmaps.build('Google', {
markers: {
clusterer: {
gridSize: 60,
maxZoom: 20,
styles: [
{
textSize: 10,
textColor: '#ff0000',
url: 'assets/creative/m1.png',
height: 60,
width: 60,
},
{
textSize: 14,
textColor: '#ffff00',
url: 'assets/creative/m2.png',
height: 60,
width: 60,
},
{
textSize: 18,
textColor: '#0000ff',
url: 'assets/creative/m3.png',
width: 60,
height: 60,
},
],
},
},
});
var handler2 = Gmaps.build('Google');
var current;
function initialize() {
handler.buildMap({ internal: {id: 'map'} }, function() {
markers_json = <%= raw @hash.to_json %>;
markers = _.map(markers_json, function (marker_json) {
marker = handler.addMarker(marker_json);
handler.fitMapToBounds();
_.extend(marker, marker_json);
return marker;
});
getLocation();
markers.map(function (elem, index) {
google.maps.event.addListener(elem.getServiceObject(), 'click', function (evt) {
var id = elem.id,
number = elem.number,
name = elem.name,
zipcode = elem.zipcode,
tabid = elem.tabid,
latitude = elem.latitude,
longitude = elem.longitude;
$('.name').html('<h3 class=\'panel-title\'><i class=\'fa fa-id-card\'></i>' + number + '</h3>');
$('.paneltb').html('<thead><tr><th>Panel</th><th>Location</th><th>Tab ID</th><th>Zip Code</th><th>Latitude</th><th>Longitude</th></tr></thead><tbody><tr><td>' + number + '</td><td>' + name + '</td><td>' + tabid + '</td><td>' + zipcode + '</td><td>' + latitude + '</td><td>' + longitude + '</td></tr></tbody>');
pos = new google.maps.LatLng(latitude, longitude);
var div = document.getElementById('map2');
var sv = new google.maps.StreetViewPanorama(div);
sv.setPosition(pos);
sv.setVisible(true);
// find the heading by looking from the google car pos to the venue pos
var service = new google.maps.StreetViewService();
service.getPanoramaByLocation(pos, 50, function (result, status) {
if (status == google.maps.StreetViewStatus.OK)
{
carPos = result.location.latLng;
heading = google.maps.geometry.spherical.computeHeading(carPos, pos);
sv.setPov({ heading: heading, pitch: 0, zoom: 1 });
}
});
$('#myModal').modal('show');
current = elem;
});
});
});
// Create the search box and link it to the UI element.
}
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(displayOnMap);
} else {
navigator.geolocation.getCurrentPosition(displayOnMapError);
}
}
function displayOnMap(position) {
marker2 = handler.addMarker({
lat: position.coords.latitude,
lng: position.coords.longitude,
picture: {
url: "<%= asset_path 'creative/1499326997_Untitled-2-01.png' %>",
width: 48,
height: 48,
},
infowindow: 'You are Here!',
});
handler.map.centerOn(marker2);
handler.getMap().setZoom(10);
}
function displayOnMapError(position) {
marker2 = handler.addMarker({
lat: 34.0522,
lng: -118.2437,
picture: {
url: "<%= asset_path 'creative/1499326997_Untitled-2-01.png' %>",
width: 48,
height: 48,
},
});
handler.map.centerOn(marker2);
handler.getMap().setZoom(10);
}
initialize();
</script>
यह आवश्यक कोड है जो मुझे आवश्यक जानकारी के साथ पॉप अप करने के लिए मोडल प्राप्त करने के लिए मूल कोड था।
$(".name").html("<h3 class='panel-title'><i class='fa fa-id-card'></i>"+number+"</h3>");
$(".paneltb").html("<thead><tr><th>Panel</th><th>Location</th><th>Tab ID</th><th>Zip Code</th><th>Latitude</th><th>Longitude</th></tr></thead><tbody><tr><td>"+number+"</td><td>"+ name + "</td><td>"+tabid+"</td><td>"+zipcode+"</td><td>"+latitude+"</td><td>"+longitude+"</td></tr></tbody>");
$('#myModal').modal('show');
current = elem;
मोडल निम्नलिखित कोड जोड़ा गया है के अंदर सड़क दृश्य जोड़ने के लिए:
pos = new google.maps.LatLng(latitude, longitude);
var div = document.getElementById('map2');
var sv = new google.maps.StreetViewPanorama(div);
sv.setPosition(pos);
sv.setVisible(true);
// find the heading by looking from the google car pos to the venue pos
var service = new google.maps.StreetViewService();
service.getPanoramaByLocation(pos, 50, function (result, status) {
if (status == google.maps.StreetViewStatus.OK) {
carPos = result.location.latLng;
heading = google.maps.geometry.spherical.computeHeading(carPos, pos);
sv.setPov({ heading: heading, pitch: 0, zoom: 1 });
}
});
आदेश वर्तमान अक्षांश और लंबे समय से सड़क दृश्य में पारित करने के लिए, मैं इसे डाल करने के लिए किया था उसी कार्य के अंदर जिस पर मोडल को बुलाया जा रहा है।
अद्यतन
मैं कैसे स्थापित करने के लिए समझ नहीं सकता var sv = new google.maps.StreetViewPanorama(div);
तो यह एक बार सेट और एक ही नक्शे मोडल की प्रत्येक आवृत्ति शुरू करने और एक नया उदाहरण को पुनः आरंभ करने की कोशिश कर के बजाय कहा जाता है के लिए पुन: उपयोग किया जाता है।
अद्यतन 2
मैं समझ नहीं कैसे शुरू में इस हिस्से को प्रारंभ करने के लिए:
var sv = new google.maps.StreetViewPanorama(div);
तो जब मैं एक मॉडल को खोलने के लिए यह एक नया नक्शा यह सिर्फ एक ही नक्शे पुनः उपयोग कर लेता प्रदर्शित नहीं होता है। मैं एक और समारोह लिखने के इच्छुक हूं लेकिन मुझे कुछ मार्गदर्शन की ज़रूरत है।
अद्यतन किसी और मैंने देखा है 3
कुछ कि जब मैं एक मार्कर पर क्लिक करें यह सड़क दृश्य मोडल में अपने वर्ग भरने दिखाएगा है। जब मैं एक और एक पर क्लिक करें कभी कभी यह सब पर नहीं दिखाया जाएगा लेकिन ज्यादातर मामलों में, यह पता चलता है, लेकिन बहुत ही इस छवि में के रूप में कोने में छोटे:
मैं भी वर्ग widget-scene-canvas
के लिए कि कोड देखा जो Google मानचित्र से आता है, वह स्वयं को अपने स्वयं के आईडी स्टाइल के माध्यम से मूल रूप से बदलता रहता है जब मैं अलग-अलग समय पर पहले मानचित्र से अधिक पर क्लिक करता हूं।
यह अपने कोड सही सड़क दृश्य के नीचे एक मॉडल है:
यहाँ मेरी वेब अनुप्रयोग के नक्शे हिस्से के लिए अंतिम कोड है। –
$ ('# myModal')। मोडल ('शो') वर्तमान = elem; }); –
मुझे नहीं पता कि आप एक ट्यूटोरियल का उपयोग करते हैं, लेकिन वैसे भी, मेरा सुझाव है कि आप उस स्क्रिप्ट से मोडल खोलने और बंद करने के साथ जो कुछ भी करना चाहते हैं उसे ले जाएं, और उसके बाद 'lnglat' को सड़क दृश्य उदाहरण में हर बार पास करें उपयोगकर्ता जो भी इवेंटबिन्डर चाहता है उसे खोलता है। और, जो मैं देख सकता हूं, आप पहले ही ऐसा कर रहे हैं, इसलिए यह बहुत मुश्किल नहीं होना चाहिए। – Crashtor