google map in tabing remove searchbar if we come back to tab again











up vote
0
down vote

favorite












I am using google map with Baidu map. both of them comes through ajax request when we click on button specified their name. first-time google map appears with search box when I click on Baidu map and come back to google map search field was gone. If I tried to append or clone search field then search field stopped working.
Code I am using:



function initMap() {
// var locations = '<?php echo $location ?>'';
var icon = '<?= IMG_URL; ?>location.png';

var newarr = Array();
map = new google.maps.Map(document.getElementById('map'),{
zoom: 4,
minZoom: 3,
maxZoom: 20,
center: {lat: 4.0633, lng: 102.2164},
mapTypeId: 'roadmap',
gestureHandling: 'greedy'
});


var infowindow = new google.maps.InfoWindow();

markers = locations.map(function(location, i) {
markers1 = new google.maps.Marker({
position: location,
id: location['id'],
html: location['html'],
icon : icon,
map: map
});
google.maps.event.addListener(markers1, 'click', function() {
infowindow.setContent(this.html);
infowindow.open(map, this);
});
return markers1;
});
if (typeof google === 'object' && typeof google.maps === 'object') {
//alert("load");
$('#check').html('load');
}else{
//alert("unload");
$('#check').html('unload');
}
var mcOptions = {imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m', gridSize: 40, maxZoom: 20, zoomOnClick: false, minimumClusterSize: 2};

// Add a marker clusterer to manage the markers.
var markerCluster = new MarkerClusterer(map, markers, mcOptions);

//console.log(markerCluster);
google.maps.event.addListener(markerCluster, 'clusterclick', function(cluster){

var clMarkers = cluster.getMarkers();
var newarr = Array();
clMarkers.forEach(function(element) {
newarr.push(element.id);
});


$.ajax({
url: 'property_scroll.php',
data: {"id": newarr},
type: 'post',
success: function(result){
//alert(result);
$("#show_property").html(result);
}
});
});

// Create the search box and link it to the UI element.
var input = document.getElementById('pac-input');
//var input = '<input id="pac-input" class="form-control controls" placeholder="Enter Keyword" type="text">';
//var input = /** @type {HTMLInputElement} */(document.getElementById('pac-input').clone());
var searchBox = new google.maps.places.SearchBox(input);
map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);

// Bias the SearchBox results towards current map's viewport.
map.addListener('bounds_changed', function() {
searchBox.setBounds(map.getBounds());
});

markers = ;
// Listen for the event fired when the user selects a prediction and retrieve
// more details for that place.
searchBox.addListener('places_changed', function() {
var places = searchBox.getPlaces();

if (places.length == 0) {
return;
}
// Clear out the old markers.
/* markers.forEach(function(marker) {
marker.setMap(null);
});*/
markers = ;

// For each place, get the icon, name and location.
var bounds = new google.maps.LatLngBounds();
places.forEach(function(place) {
if (!place.geometry) {
console.log("Returned place contains no geometry");
return;
}
var icon = {
url: place.icon,
size: new google.maps.Size(71, 71),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(17, 34),
scaledSize: new google.maps.Size(25, 25)
};

// Create a marker for each place.
/* markers.push(new google.maps.Marker({
map: map,
icon: icon,
title: place.name,
position: place.geometry.location
}));*/

if (place.geometry.viewport) {
// Only geocodes have viewport.
bounds.union(place.geometry.viewport);
} else {
bounds.extend(place.geometry.location);
}
});
map.fitBounds(bounds);
});
}









share|improve this question






















  • Please provide a Minimal, Complete, and Verifiable example that demonstrates your issue.
    – geocodezip
    Nov 19 at 6:17










  • There are two buttons one for google map and another for Baidu map when we click on Baidu map and click again on google map then search bar disappears.
    – VikashThakur
    Nov 19 at 6:33










  • Please provide a Minimal, Complete, and Verifiable example in the question itself, not (just) a link to a broken page.
    – geocodezip
    Nov 19 at 7:43










  • That is not your complete code and it can not be used to reproduce the problem. Where is your HTML? Where is your CSS? ...
    – MrUpsidown
    Nov 19 at 10:26















up vote
0
down vote

favorite












I am using google map with Baidu map. both of them comes through ajax request when we click on button specified their name. first-time google map appears with search box when I click on Baidu map and come back to google map search field was gone. If I tried to append or clone search field then search field stopped working.
Code I am using:



function initMap() {
// var locations = '<?php echo $location ?>'';
var icon = '<?= IMG_URL; ?>location.png';

var newarr = Array();
map = new google.maps.Map(document.getElementById('map'),{
zoom: 4,
minZoom: 3,
maxZoom: 20,
center: {lat: 4.0633, lng: 102.2164},
mapTypeId: 'roadmap',
gestureHandling: 'greedy'
});


var infowindow = new google.maps.InfoWindow();

markers = locations.map(function(location, i) {
markers1 = new google.maps.Marker({
position: location,
id: location['id'],
html: location['html'],
icon : icon,
map: map
});
google.maps.event.addListener(markers1, 'click', function() {
infowindow.setContent(this.html);
infowindow.open(map, this);
});
return markers1;
});
if (typeof google === 'object' && typeof google.maps === 'object') {
//alert("load");
$('#check').html('load');
}else{
//alert("unload");
$('#check').html('unload');
}
var mcOptions = {imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m', gridSize: 40, maxZoom: 20, zoomOnClick: false, minimumClusterSize: 2};

// Add a marker clusterer to manage the markers.
var markerCluster = new MarkerClusterer(map, markers, mcOptions);

//console.log(markerCluster);
google.maps.event.addListener(markerCluster, 'clusterclick', function(cluster){

var clMarkers = cluster.getMarkers();
var newarr = Array();
clMarkers.forEach(function(element) {
newarr.push(element.id);
});


$.ajax({
url: 'property_scroll.php',
data: {"id": newarr},
type: 'post',
success: function(result){
//alert(result);
$("#show_property").html(result);
}
});
});

// Create the search box and link it to the UI element.
var input = document.getElementById('pac-input');
//var input = '<input id="pac-input" class="form-control controls" placeholder="Enter Keyword" type="text">';
//var input = /** @type {HTMLInputElement} */(document.getElementById('pac-input').clone());
var searchBox = new google.maps.places.SearchBox(input);
map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);

// Bias the SearchBox results towards current map's viewport.
map.addListener('bounds_changed', function() {
searchBox.setBounds(map.getBounds());
});

markers = ;
// Listen for the event fired when the user selects a prediction and retrieve
// more details for that place.
searchBox.addListener('places_changed', function() {
var places = searchBox.getPlaces();

if (places.length == 0) {
return;
}
// Clear out the old markers.
/* markers.forEach(function(marker) {
marker.setMap(null);
});*/
markers = ;

// For each place, get the icon, name and location.
var bounds = new google.maps.LatLngBounds();
places.forEach(function(place) {
if (!place.geometry) {
console.log("Returned place contains no geometry");
return;
}
var icon = {
url: place.icon,
size: new google.maps.Size(71, 71),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(17, 34),
scaledSize: new google.maps.Size(25, 25)
};

// Create a marker for each place.
/* markers.push(new google.maps.Marker({
map: map,
icon: icon,
title: place.name,
position: place.geometry.location
}));*/

if (place.geometry.viewport) {
// Only geocodes have viewport.
bounds.union(place.geometry.viewport);
} else {
bounds.extend(place.geometry.location);
}
});
map.fitBounds(bounds);
});
}









share|improve this question






















  • Please provide a Minimal, Complete, and Verifiable example that demonstrates your issue.
    – geocodezip
    Nov 19 at 6:17










  • There are two buttons one for google map and another for Baidu map when we click on Baidu map and click again on google map then search bar disappears.
    – VikashThakur
    Nov 19 at 6:33










  • Please provide a Minimal, Complete, and Verifiable example in the question itself, not (just) a link to a broken page.
    – geocodezip
    Nov 19 at 7:43










  • That is not your complete code and it can not be used to reproduce the problem. Where is your HTML? Where is your CSS? ...
    – MrUpsidown
    Nov 19 at 10:26













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am using google map with Baidu map. both of them comes through ajax request when we click on button specified their name. first-time google map appears with search box when I click on Baidu map and come back to google map search field was gone. If I tried to append or clone search field then search field stopped working.
Code I am using:



function initMap() {
// var locations = '<?php echo $location ?>'';
var icon = '<?= IMG_URL; ?>location.png';

var newarr = Array();
map = new google.maps.Map(document.getElementById('map'),{
zoom: 4,
minZoom: 3,
maxZoom: 20,
center: {lat: 4.0633, lng: 102.2164},
mapTypeId: 'roadmap',
gestureHandling: 'greedy'
});


var infowindow = new google.maps.InfoWindow();

markers = locations.map(function(location, i) {
markers1 = new google.maps.Marker({
position: location,
id: location['id'],
html: location['html'],
icon : icon,
map: map
});
google.maps.event.addListener(markers1, 'click', function() {
infowindow.setContent(this.html);
infowindow.open(map, this);
});
return markers1;
});
if (typeof google === 'object' && typeof google.maps === 'object') {
//alert("load");
$('#check').html('load');
}else{
//alert("unload");
$('#check').html('unload');
}
var mcOptions = {imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m', gridSize: 40, maxZoom: 20, zoomOnClick: false, minimumClusterSize: 2};

// Add a marker clusterer to manage the markers.
var markerCluster = new MarkerClusterer(map, markers, mcOptions);

//console.log(markerCluster);
google.maps.event.addListener(markerCluster, 'clusterclick', function(cluster){

var clMarkers = cluster.getMarkers();
var newarr = Array();
clMarkers.forEach(function(element) {
newarr.push(element.id);
});


$.ajax({
url: 'property_scroll.php',
data: {"id": newarr},
type: 'post',
success: function(result){
//alert(result);
$("#show_property").html(result);
}
});
});

// Create the search box and link it to the UI element.
var input = document.getElementById('pac-input');
//var input = '<input id="pac-input" class="form-control controls" placeholder="Enter Keyword" type="text">';
//var input = /** @type {HTMLInputElement} */(document.getElementById('pac-input').clone());
var searchBox = new google.maps.places.SearchBox(input);
map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);

// Bias the SearchBox results towards current map's viewport.
map.addListener('bounds_changed', function() {
searchBox.setBounds(map.getBounds());
});

markers = ;
// Listen for the event fired when the user selects a prediction and retrieve
// more details for that place.
searchBox.addListener('places_changed', function() {
var places = searchBox.getPlaces();

if (places.length == 0) {
return;
}
// Clear out the old markers.
/* markers.forEach(function(marker) {
marker.setMap(null);
});*/
markers = ;

// For each place, get the icon, name and location.
var bounds = new google.maps.LatLngBounds();
places.forEach(function(place) {
if (!place.geometry) {
console.log("Returned place contains no geometry");
return;
}
var icon = {
url: place.icon,
size: new google.maps.Size(71, 71),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(17, 34),
scaledSize: new google.maps.Size(25, 25)
};

// Create a marker for each place.
/* markers.push(new google.maps.Marker({
map: map,
icon: icon,
title: place.name,
position: place.geometry.location
}));*/

if (place.geometry.viewport) {
// Only geocodes have viewport.
bounds.union(place.geometry.viewport);
} else {
bounds.extend(place.geometry.location);
}
});
map.fitBounds(bounds);
});
}









share|improve this question













I am using google map with Baidu map. both of them comes through ajax request when we click on button specified their name. first-time google map appears with search box when I click on Baidu map and come back to google map search field was gone. If I tried to append or clone search field then search field stopped working.
Code I am using:



function initMap() {
// var locations = '<?php echo $location ?>'';
var icon = '<?= IMG_URL; ?>location.png';

var newarr = Array();
map = new google.maps.Map(document.getElementById('map'),{
zoom: 4,
minZoom: 3,
maxZoom: 20,
center: {lat: 4.0633, lng: 102.2164},
mapTypeId: 'roadmap',
gestureHandling: 'greedy'
});


var infowindow = new google.maps.InfoWindow();

markers = locations.map(function(location, i) {
markers1 = new google.maps.Marker({
position: location,
id: location['id'],
html: location['html'],
icon : icon,
map: map
});
google.maps.event.addListener(markers1, 'click', function() {
infowindow.setContent(this.html);
infowindow.open(map, this);
});
return markers1;
});
if (typeof google === 'object' && typeof google.maps === 'object') {
//alert("load");
$('#check').html('load');
}else{
//alert("unload");
$('#check').html('unload');
}
var mcOptions = {imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m', gridSize: 40, maxZoom: 20, zoomOnClick: false, minimumClusterSize: 2};

// Add a marker clusterer to manage the markers.
var markerCluster = new MarkerClusterer(map, markers, mcOptions);

//console.log(markerCluster);
google.maps.event.addListener(markerCluster, 'clusterclick', function(cluster){

var clMarkers = cluster.getMarkers();
var newarr = Array();
clMarkers.forEach(function(element) {
newarr.push(element.id);
});


$.ajax({
url: 'property_scroll.php',
data: {"id": newarr},
type: 'post',
success: function(result){
//alert(result);
$("#show_property").html(result);
}
});
});

// Create the search box and link it to the UI element.
var input = document.getElementById('pac-input');
//var input = '<input id="pac-input" class="form-control controls" placeholder="Enter Keyword" type="text">';
//var input = /** @type {HTMLInputElement} */(document.getElementById('pac-input').clone());
var searchBox = new google.maps.places.SearchBox(input);
map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);

// Bias the SearchBox results towards current map's viewport.
map.addListener('bounds_changed', function() {
searchBox.setBounds(map.getBounds());
});

markers = ;
// Listen for the event fired when the user selects a prediction and retrieve
// more details for that place.
searchBox.addListener('places_changed', function() {
var places = searchBox.getPlaces();

if (places.length == 0) {
return;
}
// Clear out the old markers.
/* markers.forEach(function(marker) {
marker.setMap(null);
});*/
markers = ;

// For each place, get the icon, name and location.
var bounds = new google.maps.LatLngBounds();
places.forEach(function(place) {
if (!place.geometry) {
console.log("Returned place contains no geometry");
return;
}
var icon = {
url: place.icon,
size: new google.maps.Size(71, 71),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(17, 34),
scaledSize: new google.maps.Size(25, 25)
};

// Create a marker for each place.
/* markers.push(new google.maps.Marker({
map: map,
icon: icon,
title: place.name,
position: place.geometry.location
}));*/

if (place.geometry.viewport) {
// Only geocodes have viewport.
bounds.union(place.geometry.viewport);
} else {
bounds.extend(place.geometry.location);
}
});
map.fitBounds(bounds);
});
}






google-maps






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 at 4:11









VikashThakur

73




73












  • Please provide a Minimal, Complete, and Verifiable example that demonstrates your issue.
    – geocodezip
    Nov 19 at 6:17










  • There are two buttons one for google map and another for Baidu map when we click on Baidu map and click again on google map then search bar disappears.
    – VikashThakur
    Nov 19 at 6:33










  • Please provide a Minimal, Complete, and Verifiable example in the question itself, not (just) a link to a broken page.
    – geocodezip
    Nov 19 at 7:43










  • That is not your complete code and it can not be used to reproduce the problem. Where is your HTML? Where is your CSS? ...
    – MrUpsidown
    Nov 19 at 10:26


















  • Please provide a Minimal, Complete, and Verifiable example that demonstrates your issue.
    – geocodezip
    Nov 19 at 6:17










  • There are two buttons one for google map and another for Baidu map when we click on Baidu map and click again on google map then search bar disappears.
    – VikashThakur
    Nov 19 at 6:33










  • Please provide a Minimal, Complete, and Verifiable example in the question itself, not (just) a link to a broken page.
    – geocodezip
    Nov 19 at 7:43










  • That is not your complete code and it can not be used to reproduce the problem. Where is your HTML? Where is your CSS? ...
    – MrUpsidown
    Nov 19 at 10:26
















Please provide a Minimal, Complete, and Verifiable example that demonstrates your issue.
– geocodezip
Nov 19 at 6:17




Please provide a Minimal, Complete, and Verifiable example that demonstrates your issue.
– geocodezip
Nov 19 at 6:17












There are two buttons one for google map and another for Baidu map when we click on Baidu map and click again on google map then search bar disappears.
– VikashThakur
Nov 19 at 6:33




There are two buttons one for google map and another for Baidu map when we click on Baidu map and click again on google map then search bar disappears.
– VikashThakur
Nov 19 at 6:33












Please provide a Minimal, Complete, and Verifiable example in the question itself, not (just) a link to a broken page.
– geocodezip
Nov 19 at 7:43




Please provide a Minimal, Complete, and Verifiable example in the question itself, not (just) a link to a broken page.
– geocodezip
Nov 19 at 7:43












That is not your complete code and it can not be used to reproduce the problem. Where is your HTML? Where is your CSS? ...
– MrUpsidown
Nov 19 at 10:26




That is not your complete code and it can not be used to reproduce the problem. Where is your HTML? Where is your CSS? ...
– MrUpsidown
Nov 19 at 10:26

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53368201%2fgoogle-map-in-tabing-remove-searchbar-if-we-come-back-to-tab-again%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53368201%2fgoogle-map-in-tabing-remove-searchbar-if-we-come-back-to-tab-again%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin