Code Monkey home page Code Monkey logo

pebble-geocode-mapquest's Introduction

pebble-geocode-mapquest

pebble-geocode-mapquest provides an API to convert a location into coordinates using MapQuest's geocoding API.

Installation

pebble package pebble-geocode-mapquest

You must be using a new-style project; install the latest pebble tool and SDK and run pebble convert-project on your app if you aren't.

Usage

The following needs to be added to your app.js:

var GeocodeMapquest = require('pebble-geocode-mapquest');
var geocodeMapquest = new GeocodeMapquest();

Pebble.addEventListener('appmessage', function(e) {
    geocodeMapquest.appMessageHandler(e);
 });
// This is not a complete example, but should demonstrate the basic usage

#include <pebble-geocode-mapquest/pebble-geocode-mapquest.h>

static void geocode_fetch_callback(GeocodeMapquestCoordinates *coordinates, GeocodeMapquestStatus status) {
    APP_LOG(APP_LOG_LEVEL_INFO, "%ld", coordinates->latitude);
    APP_LOG(APP_LOG_LEVEL_INFO, "%ld", coordinates->longitude);
    ...
}

static void init(void) {
  geocode_mapquest_init();
  geocode_mapquest_set_api_key(GEOCODE_API_KEY);

  geocode_mapquest_fetch("Seattle, WA", geocode_fetch_callback)
  ...
}

static void deinit(void) {
  geocode_mapquest_deinit();
  ...
}

You must call geocode_mapquest_init() first followed by geocode_mapquest_set_api_key(), preferably in your app's init function.

It is recommended to use a preprocessor define for your MapQuest API key instead of hard coding it, if only to prevent it from being stored in your repo history: CFLAGS="-DGEOCODE_API_KEY=\"thisismyapikey\" pebble build"

Before your app quits, you must call geocode_mapquest_deinit().

geocode_mapquest_fetch() takes a location string and a callback with the results of the geocode operation. If the operation failed for some reason that will be reflected in the status parameter to the callback.

geocode_mapquest_save() and geocode_mapquest_load() will save or load the most recent geocoding to the specified key. This is a good way to avoid excessive calls to the MapQuest API. Save the results and refresh only if the user specifies a different location.

pebble-geocode-mapquest's People

Contributors

dmorgan81 avatar

Stargazers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.