This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

[closed] get Geolocation on click in OSM Map

0

Hi,

I need to display a marker on map when i clicked on the map and also i have to fetch the address of that gps point

OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
defaultHandlerOptions: { 'single': true, 'double': false, 'pixelTolerance': 0, 'stopSingle': false, 'stopDouble': false },

initialize: function(options) {
    this.handlerOptions = OpenLayers.Util.extend(
    {}, this.defaultHandlerOptions
        );
    OpenLayers.Control.prototype.initialize.apply(
        this, arguments
        ); 
    this.handler = new OpenLayers.Handler.Click(
        this, {
            'click': this.trigger
        }, this.handlerOptions
        );
},

trigger: function(e) {
    var lonlat = map.getLonLatFromPixel(e.xy);
    alert("You clicked near " + lonlat.lat + " N, " +
        + lonlat.lon + " E");
}

}); var map; function showGeoFenceMap(){
map = new OpenLayers.Map('geofencMap');
map.addLayers([new OpenLayers.Layer.OSM()]); map.addControl(new OpenLayers.Control.LayerSwitcher()); map.zoomToMaxExtent();
var click = new OpenLayers.Control.Click(); map.addControl(click); click.activate(); }

I have tried this am not getting some strange values. i want to use default layer.

Thanks, Kiran

asked 21 Jun '13, 11:26

amkiranv's gravatar image

amkiranv
1333
accept rate: 0%

closed 24 Jun '13, 22:13

SimonPoole's gravatar image

SimonPoole ♦
44.7k13326701

The question has been closed for the following reason “Question is off-topic or not relevant” by SimonPoole 24 Jun ‘13, 22:13


One Answer:

0

This is a specific OpenLayers question and should be asked on an appropriate OL forum.

answered 24 Jun '13, 22:13

SimonPoole's gravatar image

SimonPoole ♦
44.7k13326701
accept rate: 18%

edited 25 Jun '13, 12:51

Source code available on GitHub .