{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Choose my Geolocator\n", "\n", "Given there's so many options on geolocator APIs, here I'm trying a few options.\n", "\n", "The goal is to pinpoint Wharton's [Huntsman Hall](http://www.facilities.upenn.edu/maps/locations/huntsman-hall-jon-m) from its address, and locate it on [Mapbox](https://www.mapbox.com/) service\n", "\n", "I now have this running at http://wtak23.github.io/plotly_mapbox.html\n", "\n", "**Table of Contents**\n", "\n", "
\n", "" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# get my mapbox token\n", "from os.path import expanduser\n", "\n", "with open(expanduser('~/mapbox-token-tak'), 'r') as f:\n", " mapbox_access_token = f.read()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Try to pinpoint Huntsman Hall\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# address of hunstman hall\n", "huntsman_address = '3730 Walnut St, Philadelphia, PA' " ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Walnut Street, University City, Philadelphia, Philadelphia County, Pennsylvania, 19104, United States of America\n", "(39.9514112, -75.1808949)\n" ] } ], "source": [ "#https://wiki.openstreetmap.org/wiki/Nominatim\n", "# (turned out to be the most robust in my experience)\n", "from geopy.geocoders import Nominatim\n", "\n", "geolocator = Nominatim()\n", "location = geolocator.geocode(huntsman_address)\n", "print(location.address)\n", "print((location.latitude, location.longitude))\n", "lat = location.latitude\n", "lon = location.longitude\n", "\n", "# below threw an exception saying it cannot *locate* Huntsman..\n", "# from geopy.geocoders import GeocoderDotUS\n", "# geolocator = GeocoderDotUS(format_string=\"%s, Philadelphia PA\")\n", "# geolocator.geocode('241 South 49th Street')\n", "\n", "# geolocator = GeocoderDotUS(format_string=\"%s, Cleveland OH\")\n", "# address, (latitude, longitude) = geolocator.geocode(\"11111 Euclid Ave\")\n", "# print(address, latitude, longitude)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import plotly.plotly as py\n", "from plotly.graph_objs import Data,Scattermapbox,Marker,Layout" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "