NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

I'm currently in the very beginning of exploring the maps possibilities, at the moment by using Google Maps JS v3 API. I have a database running, with a lot of addresses (in form of following format: "Street" "house-number", "postal-code" ), which I'm extracting in XML by using PHP code. My currently experiment with Google maps api works fine, first by reading my XML document generated with my PHP page, and the transforming each address in the XML into latlng by using Googles geocode service. The problem among others, that I'm hitting the limitations of the Google geocode, and for my purpose of use with the map service, it would violate with the publicity demand by their license rules (not becuase the code is "secret", but because the page is running internally.

Anyways, I'm now searching for a more flexible, and more open source friendly source. And thats why I'm here, trying to figure out how to work with OSM etc.

I read some information about "Open Geocode Service with MapQuest" link But I can't figure out, how to turn the request into lng and lat that I can turn into markers?? My aim is to via geocode, turn each of my address in the database, into a marker on the map (preferable OSM).

asked 23 Jan '13, 13:52

Grmihel's gravatar image

Grmihel
16111
accept rate: 0%

edited 02 Feb '13, 16:17

SimonPoole's gravatar image

SimonPoole ♦
44.7k13326701


I already did some research around, but it seems to me to be a little hard to find an equally to Google geocode structure.

function geocodeMe(pAddress, type) {
            geocoder.geocode({
                'address': pAddress
            },
            function(result, status){
                if(status == google.maps.GeocoderStatus.OK){
                    map.setCenter(result[0].geometry.location);
                    var icon = customertypeIcons[type] || customertypeIcons['Unknown'];
                    var marker = new google.maps.Marker({
                        map: map,
                        icon: icon.icon,
                        shadow: icon.shadow,
                        position: result[0].geometry.location,
                        title: icon.title
                    });
                } else{
                    alert('Geocode was not successful for the following reason: ' + status);
                }
            });
        }

Right now with my OSM/OMQ experiment, I'm using the HTTP URL to get lat and lng from an address, and turn it into a marker on the map. But I'm getting lost in how to hand over custom parameters, and what is possible with it. My currently experiment code look like:

            function doClick(url) {
            var script = document.createElement('script');
            script.type = 'text/javascript';
            script.src = url;
            document.body.appendChild(script);
        }

        function renderGeocode(response) {
            var location = response.results[0].locations[0];
            if(location != undefined){
                //console.log(location);
                markers.addMarker(new OpenLayers.Marker(LngLat(location.latLng.lng, location.latLng.lat), icon));
                markers.addMarker(new OpenLayers.Marker(LngLat(location.latLng.lng, location.latLng.lat), icon.clone()));
            }
        }

But since the functions already run in a JS on a htm page, it seems quiet pointless doing the first codeblock. But I can't find a more smooth way to handle the geocoding block...?? Ain't it possible to use eg. Open Map Quest more like the Google.geocoder ?? (Couldn't seem to find any other threads giving me a hint to work on :( )

Edit: I'm calling the doClick function with url string as: http://open.mapquestapi.com/geocoding/v1/address?location='+address+'&callback=renderGeocode

permanent link

answered 25 Jan '13, 09:41

Grmihel's gravatar image

Grmihel
16111
accept rate: 0%

edited 25 Jan '13, 09:57

A side-note: OSM data (also google's data) is incomplete - you probably will not get a (or only get a very approximate) location for every address.

How to do geocoding with OSM data? You already mentioned the right keyword/tag. See the questions tagged geocoding (also try other tags or searches on this help page - this is a very popular topic for which you will find many answers). Shortcut - see: our docu wiki's entry about Nominatim.

If you are also searching for a JS library for displaying a map with markers, then you may want to have a look at Leaflet.

If you find some more accurate info matching your question, please add it as an answer yourself.

permanent link

answered 24 Jan '13, 00:56

aseerel4c26's gravatar image

aseerel4c26 ♦
32.6k18248554
accept rate: 18%

edited 24 Jan '13, 15:24

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×362
×133

question asked: 23 Jan '13, 13:52

question was seen: 16,702 times

last updated: 02 Feb '13, 16:17

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum