Multiple Google Street Views on the same page - google-maps

I am trying to embed two Google Street View controls on the same page, it should look something like this:
How the end result should look like
I want my visitors to use the controls on both elements to navigate around the area with their mouse. Is this possible on the same HTML page?

Example of multiple (3) streetView panoramas
(taken from various examples in the documentation, uses (but doesn't really require) JQuery.
code snippet:
function initPano() {
var panoramas = [];
panoDivs = document.getElementsByClassName('pano');
$(".pano").each(function(idx, el) {
console.log("idx=" + idx + " lat:" + parseFloat($(this).data("lat")) + " lng:" + parseFloat($(this).data("lng")) + " heading:" + parseFloat($(this).data("heading")));
var panorama = new google.maps.StreetViewPanorama(
el, {
position: {
lat: parseFloat($(this).data("lat")),
lng: parseFloat($(this).data("lng"))
},
pov: {
heading: parseFloat($(this).data("heading")),
pitch: 0
},
visible: true
});
panoramas.push(panorama);
});
}
google.maps.event.addDomListener(window, "load", initPano);
html,
body {
margin: 0;
padding: 0;
}
.pano {
height: 200px;
width: 200px;
margin: 2px;
padding: 2px;
}
.col {
height: 200px;
width: 620px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div class="col">
<div style="float:left" class="pano" data-lat="42.345573" data-lng="-71.098326" data-heading="34"></div>
<div style="float:right" class="pano" data-lat="40.729884" data-lng="-73.990988" data-heading="265"></div>
<div class="pano" data-lat="37.869260" data-lng="-122.254811" data-heading="165"></div>
</div>

Related

Google map API won't show

I cannot get google maps in my view
Code
// html
<div id="map"></div>
// css
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
// scripts
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=PLACED MY CODE HERE... &callback=initMap"></script>
<script>
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 8
});
}
</script>
RESULT
Nothing shows in my view & no error in console or network tab.
Any idea?
try use a valid width too eg: (just for test)
// css
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 640px;
width:800px;
}

How to set up a google map, which allows users to add new markers but not to edit or change already existing ones?

I know my question isn't very specific and quite general. Sorry about that. I'm new to google maps API and unsure what would be the optimal or typical approach. If you could just steer me in the general direction...
I want to set up a website, with the following functionality:
displaying a map with markers, highlighting POI's of the users
everyone should be able to add additional markers (ideally with title, description and a photo)
BUT: the old markers are not to be changed by anyone but me
Do I have to worry about API requests? For example, if 100 markers are set and 1000 users load the website would that already result in 100.000 requests?
Thanks for any help
Added the code implementation (just the client side). But little tweaks need to be made, in order to work as required.
Displaying a map with markers, highlighting POI's of the users
This need to be done with a backend server. On page load, get the details as response from the server and save it in the markers array. Once loaded iterate the array and add the markers while initializing the map.
Everyone should be able to add additional markers (ideally with title, description and a photo)
Added the functionality in the below code. But the data will not be stored in backend (it need to be implemented based on the requirements). For now, the marker details are stored in the local markers array. Make sure to add it to the array only after saving it in the database.
The old markers are not to be changed by anyone but Me.
Added those functionalities to (but only as a static). Need to check the user scope before editing/deleting the markers and it has to be implemented based on your requirements.
Do I have to worry about API requests? For example, if 100 markers are set and 1000 users load the website would that already result in 100.000 requests?
The API requests are only for maps, not for markers. As per Google Guides, 25000 requests are free per 24 hrs. Refer the pricing page for more info, if the request exceeds the free limit.
P.S : 1. Add your API key in the script. 2. Used Javascript Closures in scripting.
<!DOCTYPE html>
<html>
<head>
<style>
.googlemap
{
margin : 0 auto;
height : 600px;
width : 600px;
}
.main_content
{
display: inline-block;
height: 100px;
}
.infowin
{
width:250px;
max-height:200px;
padding : 5px;
background: #fab9b9;
display:inline-block;
}
.infowin_img
{
float:left;
margin:0;
width:70px;
height: 100%;
background: #0db99e;
}
.infowin_img > img
{
height: 100%;
width: 70px;
}
.infowin_content
{
float: left;
margin:0;
background: #1e72d3;
height:100%;
width :180px;
color:white;
padding: 5px;
overflow: scroll;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.btn_div
{
bottom: 0;
width: 100%;
margin: 0 auto;
text-align: center;
}
.button
{
padding: 3px;
width:100px;
color:white;
cursor:pointer;
border-radius: 5px;
text-align: center;
display: inline-block;
}
.edit_btn
{
border: 1px solid #277107;
background: #2e8608;
}
.edit_btn:hover
{
background: #206004;
}
.remove_btn
{
border: 1px solid #e54646;
border-radius: 5px;
background: #dd5f5f;
}
.remove_btn:hover
{
background: #e32424;
}
</style>
</head>
<body>
<div id="googlemap" class="googlemap"></div>
<div id="form" hidden>
<table>
<tr><td>Name:</td> <td><input type='text' id='name'/> </td> </tr>
<tr><td>Description:</td> <td><input type='text' id='description'/> </td> </tr>
<tr><td>Image:</td> <td><input type='file' id='photo'/> </td> </tr>
<tr><td></td> <td><input type='button' value='Save' onclick="GoogleMap.saveLocation()"/> </td> </tr>
</table>
</div>
<div id="infowin" hidden>
<div class="infowin">
<div class="main_content">
<div class="infowin_img">
<img src="dummy.jpg">
</div>
<div class="infowin_content">
<span>PLACE_NAME</span><br>
<span>PLACE_DESCRIPTION</span><br>
<span>Added by : ADDED_BY</span>
</div>
</div>
<div class="btn_div">
<div class="button edit_btn" onclick="GoogleMap.editLocation()">Edit Location</div>
<div class="button remove_btn" onclick="GoogleMap.removeLocation()">Remove Location</div>
</div>
</div>
</div>
<script>
var CommonUtil = (function(){
return {
getInputValue : function(id){
return document.getElementById(id).value;
},
setInputValue : function(id, value){
document.getElementById(id).value = value;
}
};
})();
var GoogleMap = (function(){
var map, selectedmarker, markers=[], infowindow;
var formcontent = document.getElementById("form").innerHTML,
detailscontent = document.getElementById("infowin").innerHTML;
return {
initialize : function(){
map = new google.maps.Map(document.getElementById('googlemap'), {
center: new google.maps.LatLng(52.302516, 16.414546), //Setting Initial Position
zoom: 6,
});
map.addListener("click",function(event){
GoogleMap.addLocation(event.latLng);
})
},
addLocation : function(latlng){
var marker = new google.maps.Marker({
position: latlng,
map: map,
label: markers.length+1
});
marker.addListener("click",function(){
selectedmarker=this;
GoogleMap.showPlaceDetailsToUser(this);
});
GoogleMap.getPlaceDetailsFromUser(marker);
markers.push(marker);
selectedmarker=marker;
},
removeLocation : function(){
markers.splice(markers.indexOf(selectedmarker),1);
if(selectedmarker)
{
selectedmarker.setMap(null);
}
},
editLocation : function(){
GoogleMap.showPlaceDetailsToUser(selectedmarker,true);
CommonUtil.setInputValue("name",selectedmarker.placeInfo.name);
CommonUtil.setInputValue("description",selectedmarker.placeInfo.description);
CommonUtil.setInputValue("photo",selectedmarker.placeInfo.photo);
},
saveLocation : function(){
selectedmarker.placeInfo = selectedmarker.placeInfo || {};
selectedmarker.placeInfo.name = CommonUtil.getInputValue("name")
selectedmarker.placeInfo.description = CommonUtil.getInputValue("description");
selectedmarker.placeInfo.photo = CommonUtil.getInputValue("photo");
selectedmarker.placeInfo.addedBy = Math.random().toString(36).substr(2, 5);
GoogleMap.showPlaceDetailsToUser(selectedmarker);
},
getPlaceDetailsFromUser : function(marker){
GoogleMap.showInfoWindow(formcontent, marker);
},
showPlaceDetailsToUser : function(marker, isedit){
var content = marker.placeInfo && !isedit ? detailscontent.replace("PLACE_NAME",marker.placeInfo.name||"NO_NAME").replace("PLACE_DESCRIPTION",marker.placeInfo.description||"NO_DESCRIPTION").replace("ADDED_BY",marker.placeInfo.addedBy) : formcontent;
GoogleMap.showInfoWindow(content, marker);
},
showInfoWindow : function(content, marker){
if(infowindow) infowindow.close();
infowindow = new google.maps.InfoWindow({content:content});
infowindow.open(map, marker);
}
}
})();
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=GoogleMap.initialize" type="text/javascript"></script>
</body>
</html>

Making Input Text to open up drop down list in AngularJS

I am trying to create a directive in AngularJS which acts as Input and Select box together. Just like when you type in search textbox a dropdown list popups for assisting user to select. The selection is working fine via mouseclick, but I want my user to use arrow keys to move up and down and select on enter as well. Below is my HTML , CSS and Javascript code. Your quick assistance in this regard will be appreciated.
/*******CSS Code******/
.input-dropdown {
position: relative;
display: inline-block;
}
.input-dropdown .dropdown {
display: none;
position: absolute;
top: 100%;
left: 0;
width: 100%;
margin-top: 2px;
background: #EEE;
}
.input-dropdown .dropdown div {
cursor: pointer;
padding: 2px 5px;
}
.input-dropdown input:focus + .dropdown {
display: block;
}
/*******AngularJS Code*****************/
var app = angular.module('myApp', []);
app.controller('MainCtrl', function ($scope) {
$scope.values = ['Chrome', 'Firefox', 'IE'];
$scope.pick = function (value) {
console.log('Picked', value)
};
});
app.directive('inputDropdown', function ($compile) {
var template =
'<input ng-model="ngModel">' +
'<div class="dropdown">' +
'<div ng-repeat="value in list | filter: ngModel">' +
'<div ng-mousedown="select($event, value)">{{value}}</div>' +
'</div>' +
'</div>';
return {
restrict: 'EA',
scope: {
ngModel: '=',
list: '=',
onSelect: '&'
},
template: template,
link: function (scope, element, attrs) {
element.addClass('input-dropdown');
scope.select = function (e, value) {
scope.ngModel = value;
scope.onSelect({ $event: e, value: value });
};
}
};
});
HTML Code:
<html ng-app="myApp">
<head>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body ng-controller="MainCtrl">
<input-dropdown ng-model="preference" list="values" on-select="pick(value)"></input-dropdown> {{preference}}
</body>
</html>

Info window showing empty / blank on Google Fusion Map layers

I'm trying to make a side by side Google Fusion Map and while that seems to be working OK, when I click on a polygon, the info window shows up as blank.
I'm trying to work out why it might not be picking up and displaying the information from the table, when the rest of the data seems to be showing up.
The map is here: http://clairemiller.net/blaenaupop.html
The code I'm using to display that is:
<!DOCTYPE html>
<html>
<head>
<style>
#map_canvas { width: 335px; height: 400px; float: left}
#map_canvas2 { width: 335px; height: 400px; }
#image {float: bottom}
body { margin: 0px}
p {color: white; font-family: arial; font-size: 12px; margin: 0px; position: relative; left: 4px; top: 3px }
#left { width: 335px; height: 20px; float: left; background-color: #007A8F}
#right { width: 335px; height: 20px; float: left; background-color: #005F70}
</style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"> </script>
<script type="text/javascript">
var map;
var layer;
var layer2;
var secondMapMove = false;
var secondMapBounds = false;
function initialize() {
map = new google.maps.Map(document.getElementById('map_canvas'), {
center: new google.maps.LatLng(51.787578, -3.204393),
zoom: 12,
mapTypeId: 'roadmap'
});
var layer = new google.maps.FusionTablesLayer({
center: new google.maps.LatLng(51.5021181, -3.17909),
query: {
select: 'geometry',
from: '1F3SbppvMyF-3lcT5zrYS8S1X8JD1G2-0aQkWLPw',
}
});
layer.setMap(map);
map2 = new google.maps.Map(document.getElementById('map_canvas2'), {
zoom: 12,
mapTypeId: 'roadmap'
});
var layer2 = new google.maps.FusionTablesLayer({
center: new google.maps.LatLng(53.13359,-1.955566),
query: {
select: 'geometry',
from: '1Hf9Z80JTCiq-zWwhhSPrbifO7q9dvA_DP_BN8IY',
}
});
layer2.setMap(map2);
google.maps.event.addListener(map,'zoom_changed',function(){
if(secondMapBounds!=true) {
var tmpZoom = map.getZoom();
map2.setZoom(tmpZoom);
} else {
secondMapBounds = false;
}
});
google.maps.event.addListener(map2,'zoom_changed',function(){
secondMapBounds = true;
var tmpZoom1 = map2.getZoom();
map.setZoom(tmpZoom1);
});
google.maps.event.addListener(map,'bounds_changed',function(){
if(secondMapMove!=true) {
var tmpBounds = map.getCenter();
map2.setCenter(tmpBounds);
} else {
secondMapMove=false;
}
});
google.maps.event.addListener(map2,'bounds_changed',function(){
secondMapMove = true
var tmpBounds2 = map2.getCenter();
map.setCenter(tmpBounds2);
});
}
</script>
</head>
<body onload="initialize();">
<div class="mapMap" id="map_canvas"></div>
<div class="mapMap" id="map_canvas2"></div>
</body>
</html>
The IDs for the two tables are in there, the infowindow appears to be showing up fine on them.
I'm wondering what I've missed that is causing the infowindows to show up blank.
It doesn't show blank, it shows white.
The contents of the infoWindows are inside <p/>-elements, the background of the infoWindows is white, and this is your CSS:
p {color: white;/*......*/}
change the color
.googft-info-window p{color:#000;}

Toggle KML Layers, Infowindow isnt working

I have this code, I'm trying to toggle some kml layers. The problem is that when I click the marker it isn't showing the infowindow.
Maybe someone can show me my error.
Here is the CODE:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?key=IzaSyAvj6XNNPO8YPFbkVR8KcTl5LK1ByRHG1E&sensor=false">
</script>
<script type="text/javascript">
var map;
// lets define some vars to make things easier later
var kml = {
a: {
name: "Productores",
url: "https://maps.google.hn/maps/ms?authuser=0&vps=2&hl=es&ie=UTF8&msa=0&output=kml&msid=200984447026903306654.0004c934a224eca7c3ad4"
}
// keep adding more if you like
};
// initialize our goo
function initializeMap() {
var options = {
center: new google.maps.LatLng(13.324182,-87.080071),
zoom: 8,
mapTypeId: google.maps.MapTypeId.TERRAIN
}
map = new google.maps.Map(document.getElementById("map_canvas"), options);
createTogglers();
};
google.maps.event.addDomListener(window, 'load', initializeMap);
// the important function... kml[id].xxxxx refers back to the top
function toggleKML(checked, id) {
if (checked) {
var layer = new google.maps.KmlLayer(kml[id].url, {
preserveViewport: true,
suppressInfoWindows: true
});
// store kml as obj
kml[id].obj = layer;
kml[id].obj.setMap(map);
}
else {
kml[id].obj.setMap(null);
delete kml[id].obj;
}
};
// create the controls dynamically because it's easier, really
function createTogglers() {
var html = "<form><ul>";
for (var prop in kml) {
html += "<li id=\"selector-" + prop + "\"><input type='checkbox' id='" + prop + "'" +
" onclick='highlight(this,\"selector-" + prop + "\"); toggleKML(this.checked, this.id)' \/>" +
kml[prop].name + "<\/li>";
}
html += "<li class='control'><a href='#' onclick='removeAll();return false;'>" +
"Remove all layers<\/a><\/li>" +
"<\/ul><\/form>";
document.getElementById("toggle_box").innerHTML = html;
};
function removeAll() {
for (var prop in kml) {
if (kml[prop].obj) {
kml[prop].obj.setMap(null);
delete kml[prop].obj;
}
}
};
// Append Class on Select
function highlight(box, listitem) {
var selected = 'selected';
var normal = 'normal';
document.getElementById(listitem).className = (box.checked ? selected: normal);
};
</script>
<style type="text/css">
.selected { font-weight: bold; }
</style>
</head>
<body>
<div id="map_canvas" style="width: 50%; height: 200px;"></div>
<div id="toggle_box" style="position: absolute; top: 200px; right: 1000px; padding: 20px; background: #fff; z-index: 5; "></div>
</body>
</html>
The "suppressInfoWindows:true" in the KmlLayerOptions in the KmlLayer constructor causes the infowindows to be suppressed.