Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8999405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:10:33+00:00 2026-06-16T00:10:33+00:00

I have two questions. First, I want to put markers in my Google map

  • 0

I have two questions. First, I want to put markers in my Google map with buttons, but I have no idea where my fault is. And second, my map should be only draggable on zoom level 16. I hope someone can help me with my problems. And here is my 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: 0px; padding: 0px }
  #map_canvas { height: 100% }
</style>
<script type="text/javascript"
    src="http://maps.google.com/maps/api/js?sensor=true">
</script>
<script type="text/javascript">
  function initialize() {
    var latlng = new google.maps.LatLng(52.502648,13.529278);
    var myOptions = {
      zoom: 15,
      center: latlng,
      disableDefaultUI: true,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      center: new google.maps.LatLng(52.502648, 13.529278),
      minZoom: 15,
      maxZoom: 16
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);

    var strictBounds = new google.maps.LatLngBounds(
    new google.maps.LatLng(52.50, 13.525),
    new google.maps.LatLng(52.506, 13.534)
    );

    // Listen for the dragend event
    google.maps.event.addListener(map, 'dragend', function() {
        if (strictBounds.contains(map.getCenter())) return;

    // We're out of bounds - Move the map back within the bounds

    var c = map.getCenter(),
         x = c.lng(),
         y = c.lat(),
         maxX = strictBounds.getNorthEast().lng(),
         maxY = strictBounds.getNorthEast().lat(),
         minX = strictBounds.getSouthWest().lng(),
         minY = strictBounds.getSouthWest().lat();

     if (x < minX) x = minX;
     if (x > maxX) x = maxX;
     if (y < minY) y = minY;
     if (y > maxY) y = maxY;

     map.setCenter(new google.maps.LatLng(y, x));
   });

   // Listen for the dragend event
    google.maps.event.addListener(map, 'bounds_changed', function() {
        if (strictBounds.contains(map.getCenter())) return;

    // We're out of bounds - Move the map back within the bounds

    var c = map.getCenter(),
         x = c.lng(),
         y = c.lat(),
         maxX = strictBounds.getNorthEast().lng(),
         maxY = strictBounds.getNorthEast().lat(),
         minX = strictBounds.getSouthWest().lng(),
         minY = strictBounds.getSouthWest().lat();

     if (x < minX) x = minX;
     if (x > maxX) x = maxX;
     if (y < minY) y = minY;
     if (y > maxY) y = maxY;

     map.setCenter(new google.maps.LatLng(y, x));
   });

   var imageBounds = new google.maps.LatLngBounds(
    new google.maps.LatLng(52.4952, 13.5189),
    new google.maps.LatLng(52.51, 13.53957)
    );

    var marker = new google.maps.Marker({
        position: new google.maps.LatLng(52.503971,13.52073),
        map:map,
        title:"Hello World!"
    });

    marker.setMap(map);

    var groundoverlay = new google.maps.GroundOverlay('pics/karte2.png', imageBounds);
    groundoverlay.setMap(map);
    groundoverlay.setOpacity(1);

  }

var wcs = [
    ['Klo1', 52.504971, 13.52063, 1],
    ['Klo2', 52.504071, 13.53023, 2],
];

var gastro = [
    ['Cafeteria', 52.504541,13.529014, 1],
    ['Imbiss', 52.500121,13.532913, 2],
];

    function setMarkers(map,locations){
        for (var i=0; i < locations.length; i++) {
            var loc = locations[i];
            var locLatLng = new google.maps.LatLng(loc[1], loc[2]);
            var locmarker = new google.maps.Marker({
                position:locLatLng,
                map:map,
                title: loc[0],
                zIndex: loc[3]
            });
        };

        locmarker.setMap(map);
    }

    /*google.maps.event.addListener(map, 'zoom_changed', function() {
        if (map.zoom!=15){map.setOptions({draggable:true});}
        else map.setOptions({draggable:false});
    });*/

</script>
</head>
<body onload="initialize()">
  <div id="map_canvas" style="width:480px; height:560px"></div>
  <form name="Test" action="">
  <input type="button" value="WCs" onclick="setMarkers(map,wcs)">
  <input type="button" value="Gastro" onclick="setMarkers(map,gastro)">
  </form>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:10:34+00:00Added an answer on June 16, 2026 at 12:10 am

    You can specify “draggable” property:

    var myOptions = {
      zoom: 15,
      center: latlng,
      disableDefaultUI: true,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      center: new google.maps.LatLng(52.502648, 13.529278),
      minZoom: 15,
      maxZoom: 16,
      draggable : false
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);
    

    And this:

    google.maps.event.addListener(map, "zoom_changed", function() {
      map.setOptions({
        draggable : map.getZoom() == 16
      });
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey everyone, I want to start using Scheme and I have two questions. First,
I have two questions. My first one is, that how can i put something
I have two questions. (First) I'm trying to make it where whenever the iPhone
I have two questions, actaully... First off, Why cant I do this: List<Object> object
I have two questions. I want to send SMSes from a web-site in PHP
I have two questions which are probably too easy, but I don't get it
I have two questions concerning fitting a gauss curve to histogram peaks. My first
I have two questions about Compound-Statement and Transactions in MySQL. FIRST: There are two
I have two basic questions. The first one is about function in other classes.
I have two questions here. How can I show the header of the pop

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.