You are not logged in.
- Topics: Active | Unanswered
Announcement
Please create new topics on the new site at community.openstreetmap.org. We expect the migration of data will take a few weeks, you can follow its progress here.***
Pages: 1
#1 2008-11-20 00:51:34
- melpelotones
- Member
- Registered: 2008-11-20
- Posts: 3
Geocoding
Hello everbody,
Many Thanks for OSM.
Can anybody explain how to perform geocoding with OSM?
I want to get programatically the lat/lon when I make
a click on the map.
Thank you in advance !
M.
Offline
#2 2008-11-20 10:30:10
- Lambertus
- Inactive

- From: Apeldoorn (NL)
- Registered: 2007-03-17
- Posts: 3,269
- Website
Re: Geocoding
Assuming that you use OpenLayers add this to your Javascript:
Init:
var click = new OpenLayers.Control.Click();
map.addControl(click);New function:
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) {
position = this.map.getLonLatFromViewPortPx(e.xy);
alert("x="+position.x+", y="+position.y);
}Mapping tools: Garmin GPSmap 60CSx, Giant Terrago 2002
Offline
#3 2008-11-20 10:34:21
- emj
- Member
- From: .se (59.3N17.99E) 0735969076
- Registered: 2006-06-18
- Posts: 949
Re: Geocoding
You can use openlayers (just copy the code for the slippy map on osm homepage). E.g. look on the javascripts of existing projects, one of the osm routing projectsdid it with openlayers.
Basically it's just adding a small callback called "handle click on map" (or something like that), and you will get a lat/lon.
Offline
#4 2008-11-20 14:20:32
- Lambertus
- Inactive

- From: Apeldoorn (NL)
- Registered: 2007-03-17
- Posts: 3,269
- Website
Re: Geocoding
emj: Double post ??? ![]()
Mapping tools: Garmin GPSmap 60CSx, Giant Terrago 2002
Offline
#5 2008-11-20 14:55:53
- emj
- Member
- From: .se (59.3N17.99E) 0735969076
- Registered: 2006-06-18
- Posts: 949
Re: Geocoding
emj: Double post ???
Strange indeed
dunno what happen (for the record I deleted it)
Offline
#6 2008-11-21 10:16:22
- melpelotones
- Member
- Registered: 2008-11-20
- Posts: 3
Re: Geocoding
Another question for geocoding.
Is there any limitation in the number of geocoding requests per day?
I.E with the google maps API there is a limit of 15.000 per day.
Thank you!
Offline
#7 2008-11-21 11:13:51
- Richard
- Member
- From: Charlbury, UK
- Registered: 2007-04-24
- Posts: 427
- Website
Re: Geocoding
OpenStreetMap doesn't aim to provide a resilient public API for data consumers. The OpenStreetMap API is primarily (though not entirely) there for the use of those editing the map. If you want to fire a large number of requests at the API, you should consider downloading planet.osm and serving the requests yourself; using OSMXAPI; or engaging a company that provides services from OSM data, such as Geofabrik or CloudMade.
Offline
#8 2008-11-21 12:10:22
- emj
- Member
- From: .se (59.3N17.99E) 0735969076
- Registered: 2006-06-18
- Posts: 949
Re: Geocoding
Another question for geocoding.
Manual geocoding as in clicking on a Javascript map is free, since it never touches the API.
Geocoding as in asking the server API what data is around a certain point, or where this street name is located, is too slow to be considered free
I'm a bit unsure what geocoding actually is in this instance.
Last edited by emj (2008-11-21 13:07:39)
Offline
#9 2008-11-21 12:28:26
- Lambertus
- Inactive

- From: Apeldoorn (NL)
- Registered: 2007-03-17
- Posts: 3,269
- Website
Re: Geocoding
If you're talking about getting the coordinate of a certain point on the map then yes, geocoding is free because the client side javascript can do that very easy. If you're firing requests to the Google API, or OSM API then it won't be free (Google because it ain't 'free', OSM because applications/mashups that use the map a lot are supposed to host their own).
Mapping tools: Garmin GPSmap 60CSx, Giant Terrago 2002
Offline
#10 2008-11-21 14:15:51
- melpelotones
- Member
- Registered: 2008-11-20
- Posts: 3
Re: Geocoding
Many thanks for your replies, everything is much clearer now ![]()
Offline
#11 2010-12-22 09:33:41
- Adhi
- Member
- Registered: 2010-12-22
- Posts: 1
Re: Geocoding
Hi,
Wish you a Happy X' Mas & New Year.
I am very new to OpenLayers API. actually i would like to plug the open street map view in to my .net based application and perform the Geocoding by user requested address. kindly let me know how to plug, and will it possible to do geocoding using openlayer API.
Can i have any basic example or any doc openlayer API.
Thanks & Regards,
Offline
#12 2010-12-22 14:46:06
- wyo
- Member

- From: Thalwil
- Registered: 2010-08-04
- Posts: 667
- Website
Re: Geocoding
trigger: function(e) { position = this.map.getLonLatFromViewPortPx(e.xy); }
I'm using just about the same code but determin the position with
trigger: function(evt) {
var lonlat = map.getLonLatFromPixel (evt.xy).transform (projMercator, projWGS84);
}What's a advantage of your solution?
See http://www.orpatec.ch/osm/tools/main.php
Wyo
Offline
#13 2010-12-22 15:22:08
- wyo
- Member

- From: Thalwil
- Registered: 2010-08-04
- Posts: 667
- Website
Re: Geocoding
OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { defaultHandlerOptions: { 'single': true, 'double': false, 'pixelTolerance': 0, 'stopSingle': false, 'stopDouble': false },
BTW how can I apply MOD_CTRL to the handler options so that only ctrl-click triggers the event?
Wyo
Offline
Pages: 1