how to geocode

updates as of 11/14/2018 (OLD)

WARNING: whatever python django is using, it uses:

    geopy-0.95.1-py2.7.egg-info
    ~/lib/python2.7/geopy-0.95.1-py2.7.egg-info

latest (in pdf) is:

    Release 1.17.0

Q: don't know what python uses geopy!!! A: see below.

wait, apparently it is this, which will import the following:

    /home/wendell/usr/local/bin/python2

    >>> from geopy.geocoders import GoogleV3
    >>> from geopy.geocoders import Bing
    >>> from geopy.geocoders import GeoNames
    >>> from geopy.geocoders import OpenMapQuest

will try new version:

    wget https://github.com/geopy/geopy/archive/master.zip
    mv master.zip geopy-master.zip
    unzip geopy-master.zip
    cd geopy-master

    /home/wendell/usr/local/bin/python2 setup.py install
    Traceback (most recent call last):
      File "setup.py", line 6, in <module>
        from setuptools import find_packages, setup
    ImportError: No module named setuptools

11/26/2018: have now moved to djleaf, which is Python3

finally moved maps over to Django2 which uses Python3, which allows use of an up-to-date geopy.

========== geopy.geocoders.Bing(key)

skyking11k@gmail.com
c...V (I think)

    Key: Show key
    Application Url:
    Key type: Basic / Dev/Test
    Created date: 11/15/2018
    Expiration date: None
    Key Status: Enabled
    Security Enabled: No

key:
    AtRTod-vdjX9V34oEQh5OTFzS7Z2dcuDp2VGvwfEquDXfQueRO8EHb2klvwSOG0e

from: https://www.bingmapsportal.com/Account

submit:1
submit:2
submit:the_address is:3701 Connecticut Ave. NW, Washington, DC 20008 US
submit:3
submit:bye
submit:4
submit:5:good
submit:5:3701 Connecticut Ave NW, Washington, DC 20008, United States
submit:5:38.9383
submit:5:-77.0599
submit:6: yipee!

>>>> works fine!

========== geopy.geocoders.GeocodeFarm

https://www.geocode.farm/geocoding/free-api-documentation/

Free Users Have 250 Per Day Limit and 4 Requests Per Second Limit (IP Based)

Free usage does not require an API Key and the free limit is 250 per day per IP address.

Just be sure to include the country at the end of the address to ensure accurate results.

>>>> works fine!

========== geopy.geocoders.Geolake

You may be required to enter your billing information in order to sign up for the Free Trial.

Signed up: skyking@ilc, z...x

https://geolake.com/account

    api key: x6RXp0JgNUgNVymWG7Ys

AttributeError: module 'geopy.geocoders' has no attribute 'Geolake'

========== geopy.geocoders.GeoNames

signed up at: http://www.geonames.org/login

rcvd email, seems good...

Error: <class 'geopy.exc.GeocoderInsufficientPrivileges'>

========== geopy.geocoders.HERE

a.k.a. HERE Geocoder API

Base URL: https://geocoder.api.here.com

register here: https://developer.here.com/plans

>>>> works fine!

can't tell if api/account includes routing, so will attempt one here:

https://route.api.here.com/routing/7.2/calculateroute.json&app_id=iHhVL3W02cDihHWduigP&app_code=e07OhHXvVW1y3loeiXVaHA

nope, how about this:

https://route.api.here.com/routing/7.2/getroute.xml?app_id=iHhVL3W02cDihHWduigP
&app_code=e07OhHXvVW1y3loeiXVaHA
&routeId=111
&mode=fastest;car
&maneuverattributes=position,link
&linkattributes=shape,DynamicSpeedInfo
&requestid=222

which is:

https://route.api.here.com/routing/7.2/getroute.xml?app_id=iHhVL3W02cDihHWduigP&app_code=e07OhHXvVW1y3loeiXVaHA&routeId=111&mode=fastest;car&maneuverattributes=position,link&linkattributes=shape,DynamicSpeedInfo&requestid=222

oops, need this:

waypoint0: '52.5160,13.3779',
waypoint1: '52.5206,13.3862',
https://route.api.here.com/routing/7.2/getroute.xml?app_id=iHhVL3W02cDihHWduigP&app_code=e07OhHXvVW1y3loeiXVaHA&routeId=111&mode=fastest;car&maneuverattributes=position,link&linkattributes=shape,DynamicSpeedInfo&requestid=222&waypoint0=52.5160,13.3779&waypoint1=52.5206,13.3862

type="ApplicationError" subtype="InvalidInputData"

s/getroute.xml/calculateroute.json/

https://route.api.here.com/routing/7.2/calculateroute.json?app_id=iHhVL3W02cDihHWduigP&app_code=e07OhHXvVW1y3loeiXVaHA&routeId=111&mode=fastest;car&maneuverattributes=position,link&linkattributes=shape,DynamicSpeedInfo&requestid=222&waypoint0=52.5160,13.3779&waypoint1=52.5206,13.3862

nope, but this does work:

wendell@webfaction:~/tmp
> cat geolocate_help_usage.sh
#!/bin/bash  -x

curl \
  -X GET \
  -H 'Content-Type: *' \
  --get 'https://route.api.here.com/routing/7.2/calculateroute.json' \
    --data-urlencode 'waypoint0=52.5160,13.3779' \
    --data-urlencode 'waypoint1=52.5206,13.3862' \
    --data-urlencode 'mode=fastest;car;traffic:enabled' \
    --data-urlencode 'app_id=iHhVL3W02cDihHWduigP' \
    --data-urlencode 'app_code=e07OhHXvVW1y3loeiXVaHA' \
    --data-urlencode 'departure=now'

SO, it DOES seem that routing is included in my $0 plan!!!

TODO: put this into js code (this is from example page):

$.ajax({
  url: 'https://route.api.here.com/routing/7.2/calculateroute.json',
  type: 'GET',
  dataType: 'jsonp',
  jsonp: 'jsoncallback',
  data: {
    waypoint0: '52.5160,13.3779',
    waypoint1: '52.5206,13.3862',
    mode: 'fastest;car;traffic:enabled',
    app_id: 'devportal-demo-20180625',
    app_code: '9v2BkviRwi9Ot26kp2IysQ',
    departure: 'now'
  },
  success: function (data) {
    alert(JSON.stringify(data));
  }
});

which is from: https://developer.here.com/api-explorer/rest/routing

========== geopy.geocoders.GoogleV3()

NOT THIS!!!

Attention: Since July 2018 Google requires each request to have an API key.

https://developers.google.com/maps/documentation/geocoding/usage-and-billing

========== geopy.geocoders.OpenMapQuest()

this is a mapquest site

https://developer.mapquest.com/documentation/open/

OLD: home page says 'wwt' email is login, but neither work; will try another geopy

========== geopy.geocoders.TomTom()

login at: https://developer.tomtom.com/user/login?destination=user/me/apps

Create app:

Below are keys you can use to access the API products associated with this application (Wendell's maps). The actual keys need to be approved for an API product so that you can access any of the URIs defined in the API product.

Consumer API Key     DwDOAQnaRA3Z83ESzw6vwtyxt0dyopG4
Key Issued           Tue, 11/27/2018 - 21:24
Expires              Never
Multiple addresses found:
411 Devonshire Ln, Burlington, NC 27215
Devonshire Ln, Burlington, NC 27215

or, with 'exactly_one=False' removed:

    exec_info: (<class 'TypeError'>, TypeError('must be str, not float',)

========== geopy.geocoders.Nominatum()

[Tue Nov 27 14:58:58.067680 2018] [wsgi:error] [pid 18056:tid 140440654939904]
[remote 127.0.0.1:39012] /home/wendell/lib/python3.6/geopy/geocoders/osm.py:143:
UserWarning: Using Nominatim with the default "geopy/1.17.0" `user_agent`
is strongly discouraged, as it violates Nominatim's ToS
https://operations.osmfoundation.org/policies/nominatim/ and may possibly
cause 403 and 429 HTTP errors. Please specify a custom `user_agent` with
`Nominatim(user_agent="my-application")` or by overriding the default
`user_agent`: `geopy.geocoders.options.default_user_agent = "my-application"`.
In geopy 2.0 this will become an exception.

then with:

    ua="wendell's ol5 map application"
    g = geopy.geocoders.Nominatim(user_agent=ua )

it works, but marker it at Devonshire + Edgewood.

========== geopy.geocoders.Photon()

Geocoder using Photon geocoding service (data based on OpenStreetMap and service provided by Komoot on https://photon.komoot.de).

    if 1:      # <class 'TypeError'>
        ua="wendell's ol5 map application"
        g = geopy.geocoders.Photon(
            format_string="%s",
            scheme="http",
            user_agent=ua )

nope.

ol-ext search nominatim:

this SO: https://stackoverflow.com/questions/25640313/nominatim-boundingbox-limit gives hints about:

    http://nominatim.openstreetmap.org/search?q=[Tankstelle]&format=xml&limit=50&viewbox=7.98435,49.40889,8.95440,48.77371&bounded=1

so it seems that using the nominatim search with options:

url: http://nominatim.openstreetmap.org/search?viewbox=<x1>,<y1>,<x2>,<y2>&bounded=1

would work, where the viewbox is limits of the map extent(?)

11/20/2019:

BIG question: mapbox vs. tomtom vs. here vs. openlayers vs. ????