Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Got this code from a teacher and I don't know what I am doing wrong! I have searched around but I can't find the error. Visual Basic shows no error.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns="">
<title>OpenLayers map</title>
<script src="" type="text/javascript"></script>
<style type ="text/css">
        position:absolute;          /*Elementets position i förhållande till andra element*/
        padding:10px;               /*Elementets avstånd från andra element (10px åt alla håll)*/
        width:600px;                /*Elementets bredd */
        height:500px;               /*Elementets höjd*/
        border:1px solid black;     /*Ram runt elementet */
<script type="text/javascript">
    //Variabel som kommer hantera OpenLayers.Map objektet.
    var map;

    //Funktion som anropas från <body> taggen, kör koden som finns i funktionen när sidan laddas (onload).
    function initMap() {
        //Initiera OpenLayers.Map objektet och tilldela till variabeln map.
        //"mapContainer" är en referens till den div (container) där du vill ha din karta.
        map = new OpenLayers.Map('mapContainer');

        //Variabeln osm tilldelas ett objekt med en OpenLayers-Lagertyp OSM(openstreetmap).
        //Ex på olika lagertyper:  OpenLayers.Layer.WMS  (vilken WMS-tjänst som helst kan kopplas in)
        //                         OpenLayers.Layer.Vector  (ett vektor lager där du kan lägga in tex punktdata)
        //                         OpenLayers.Layer.Google  (om du vill använda Googles bakgrundskartor)
        var osm = new OpenLayers.Layer.OSM();

        //Variabeln osm som innehåller Openstreetmap objektet läggs till kartobjektet genom map.addLayer()

        //När kartan initieras måste OpenLayers veta var du vill börja någonstanns, i det här fallet zoomas kartan till 
        //full utzoomning i förhållande till Openstreetmaps utbredning (extent).
        //Ett alternativ är att använda map.setCenter() då du anger exakta koordinater och zoomnivå men mer om det senare.  

share|improve this question
What kind of problem do you have? – drnextgis Dec 17 '12 at 9:22
Visual Basic or did you mean Visual Studio? – R.K. Dec 17 '12 at 12:15
I can´t make the code work :( When I start the debugger I can´t se the Openstreetmap as I should. Yes, in visual studio. – Mimmi Dec 17 '12 at 13:29

Your page is missing a map container tag and a call to the initMap() function. Basically add this to the end of your code:

  <body onload="initMap()">
    <div id="mapContainer"></div>
share|improve this answer
Sorry, i missed to copy my last code...! – Mimmi Dec 17 '12 at 13:22
This is the code after </script> : </head> <body onload="initMap()"> <div id="mapContainer"></div> </body> </html> – Mimmi Dec 17 '12 at 13:22

I don't know what your error is, and what Visual basic has to do with it.

You have most probably left out

<body onload="initmap();">
<!-- define a DIV into which the map will appear. Make it take up the whole window -->
<div style="width:100%; height:100%" id="mapContainer"></div>

to get the map loadad. The extent, zoomlevel and name of the layer is also missing, as well as some controls to zoom and choose layers.

You can look into my adaption here:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.