[GIS] Points on Google layer using OpenLayers

openlayers-2

I want to load some points, whose lat-long values are saved in a .txt file over Google maps. The following is the code which I am using for the same. The Google map layer is successfully loaded if I keep lines 1-10 & 13-17. For loading the data points I am including 11-12 lines but I am not getting any output at all. I request you to please find the error and suggest how to do the same. "data.txt" contains the lat-long values with tab delimited present in my server.

1.<html>
2.<head> 
3.<title>OpenLayers Example</title> 
4.<script src="http://openlayers.org/api/OpenLayers.js"></script> 
5.</head> 
6.<body> 
7.<div style="width:100%; height:100%" id="map"></div> 
8.<script defer="defer" type="text/javascript"> 
9.   var map = new OpenLayers.Map('map'); 
10.  var gmaplayer = new OpenLayers.Layer.Google( "Google Streets", 
       "http://maps.google.com/mapsfile=api&v=2&key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ"); 
11.  var layer = new OpenLayers.Layer.GML("Layer Name","http://localhost/data.txt", 
        {format: OpenLayers.Format.Text }); 
12.   map.addLayer(layer); 
13.   map.addLayer(gmaplayer); 
14.   map.zoomToMaxExtent(); 
15.</script> 
16.</body> 
17.</html> 

When I am replacing above 11-12 lines with

11.var pois = new OpenLayers.Layer.Text( "My Points", 
                { location:"./data.txt", 
                  projection: map.displayProjection 
                }); 
12.map.addLayer(pois);

Even then I am not able to get the output. I require some needful help from any one of you

Best Answer

I thinks there's perhaps a projection confusion between your points and the google map. In your second line n°11, you are telling OL that your points are projected in the map.displayProjection. Or you said earlier that they were in lat/long, so not projected.

Try to tell OL that the points are in the lat/long system with :

var pois = new OpenLayers.Layer.Text( "My Points", {location:"./data.txt", projection: new OpenLayers.Projection("EPSG:4326")} );