<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Marker Labels</title>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDLHKWYAEE2PDjvt6BaBH1SIs4Q93PMpQs&libraries=places"></script>
</head>
<body>
<div id="floating-panel">
<!-- Supply a default place ID for a place in Brooklyn, New York. -->
<input id="place-id" type="text" value="">
<input id="search_geo" type="button" value="Search">
</div>
<div id="map"></div>
</body>
</html>
/* 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 {
width: 440px;
}
#place-id {
width: 250px;
}
var labels = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var labelIndex = 0;
var search_markers = [];
var s_markers = [];
var markers = [];
var counter = 0;
var x_infowindow = null;
var map;
function initialize() {
var currentarea = { lat: 14.5393988, lng: 121.0521586};
map = new google.maps.Map(document.getElementById('map'), {
zoom: 1,
center: {lat:0,lng:0},
disableDefaultUI: true
});
document.getElementById('search_geo').addEventListener('click', function() {
var address = document.getElementById('place-id').value;
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': address },function(results, status) {
s_markers.forEach(function(s_mark) {
s_mark.setMap(null);
});
s_markers = [];
results.forEach(function(res){
var pos = res.geometry.location;
map.panTo(pos);
var s_mark = new google.maps.Marker({
position: pos,
title: res.formatted_address,
map: map
});
s_markers.push(s_mark);
s_mark.addListener('click', function() {
if (x_infowindow != null){
x_infowindow.close();
}
var rloc = res.geometry.location
var _lat = rloc.lat();
var _lng = rloc.lng();
var location = _lat + "," + _lng;
var loc_type = res.geometry.location_type;
var address = res.formatted_address;
var add_type = res.types;
var s_cont = '<p>Location: '+ location +'</p>';
s_cont += '<p>Location Type: '+loc_type+'</p>';
s_cont += '<p>Address: '+address+'</p>';
s_cont += '<p>Address Type :'+add_type+'</p>';
var s_infowindow = new google.maps.InfoWindow({
content: s_cont
});
s_infowindow.open(map, s_mark);
x_infowindow = s_infowindow;
});
fitsearch();
});
});
});
google.maps.event.addListener(map, 'click', function(event) {
addMarker(event.latLng, map);
});
function addMarker(location, map) {
counter++;
var marker = new google.maps.Marker({
position: location,
label: labels[labelIndex++ % labels.length],
map: map,
id: counter,
});
markers.push(marker);
var contentString = '<input onclick="deleteMarker('+counter+');" type=button value="Delete Marker">';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
marker.addListener('click', function() {
if (x_infowindow != null){
x_infowindow.close();
}
infowindow.open(map, marker);
x_infowindow = infowindow;
});
}
function setMapOnAll(map) {
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(map);
}
}
}
function clearMarkers(count) {
count = count - 1;
markers[count].setMap(null);
}
function deleteMarker(count) {
clearMarkers(count);
}
function fitsearch(){
var bounds = new google.maps.LatLngBounds();
for (var i=0; i<s_markers.length; i++) {
bounds.extend( s_markers[i].getPosition() );
}
map.fitBounds(bounds);
}
google.maps.event.addDomListener(window, 'load', initialize);
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |