API

Basics




Basic module - Render my location

This is the easiest way to integrate PocketLocator on a website. Just copy-paste this line where you want your location to show.

This will generate the following code:

document.write('30 cooper square, New-York, USA')

Preview: 30 cooper square, New-York, USA


This is the generate code if you choose Google Maps when you set your location:

document.write('<a href="https://maps.google.com/?z=14&q=30+cooper+square%2C+New-York%2C+USA" target="_blank">30 cooper square, New-York, USA</a>')

Preview: 30 cooper square, New-York, USA

See demo (using demo account location)

Note: This address is an example, it will be replace by yours




Render my location in a specific element of my page

First, if document.write() doesn't fit your needs, you can provide an id name and we will use it as an innerHTML instead.

This will generate the following code:

document.getElementById('mydiv').innerHTML = "30 cooper square, New-York, USA"

See demo (using demo account location)




Show my location only when my page is loaded

You can use the following code to request your location only when the rest of your website is fully loaded. Our server can be slow (free products don't have cache servers everywhere like Facebook does...), but that's not a reason to slow YOU down.

See demo (using demo account location)

Note: An id is needed (see "Render my location in a specific element of my page"). We put a <span id='pocketlocator'> as an example. Feel free to adapt to your needs.




Other output format

Oh great, so you want more? We don’t support SSH (yet?), but here is what we have for you:


Values

Here is the list of datas we do provide:

Label:
Full output, including link to external map service if chosen. This string may contain HTML tags if a link service is select.
This may also be a "custom text".

Full:
Contains Street name, Town nane & Country name if available.

Street:
Street name, based on Google API geocoding if the device has a GPS capability, otherwise via user submitted infos.

Town:
Town name, based on Google API geocoding if the device has a GPS capability, otherwise via user submitted infos.

Country:
Country name, based on Google API geocoding if the device has a GPS capability, otherwise via user submitted infos.

Lat:
GPS latitude. It will be empty if user device has no GPS capability.

Lng:
GPS longitude. It will be empty if user device has no GPS capability.

Mode:
Screening mode that the user has chosen during submission. Values are 'CT' for Custom text, 'STC' for Street+Town+Country, 'ST' for Street+Town, 'TC' for Town+Country, 'S' for Street only, 'T' for Town only or 'C' for Country only.

Link:
Map service choosen by user during location submission. It can be 'gmap' for Google Maps, 'bing' for Bing Maps or 'none' if the user ask for no link.


JSON object output URL:

This will output an object as the following:

{
"pocketlocator" : {
"label" : "At the office",
"full" : "30 Cooper Square, New-York, USA",
"street" : "30 Cooper Square",
"town" : "New-York",
"country" : "USA"
"lat" : "40.72809575709464"
"lng" : "-73.99128394699096"
"mode" : "CT"
"link" : "gmap"
}
}

See demo account JSON string

Note: Yes, we do support JSONP too via the regular &callback=myFunctionName. See demo (using demo account location)



XML object output URL:

This will output the following:

<?xml version="1.0"?>
<pocketlocator>
<label>At the office</label>
<full>30 Cooper Square, New-York, USA </full>
<street>30 Cooper Square</street>
<town>New-York</town>
<country>USA</country>
<lat>40.72809575709464</town>
<lng>-73.99128394699096</lng>
<mode>L</mode>
<link>gmap</link>
</pocketlocator>

See demo account XML string


Custom scope / fields:

In case you only need one or a few fields, you can set fields label separated by a coma as "fields". As an example, see the following request URL to only get lat & lng.

This will output an object as the following:

{
"pocketlocator" : {
"lat" : "40.72809575709464"
"lng" : "-73.99128394699096"
}
}

See demo account JSON string with only latitude & longitude


If you need some more example, please check out the few examples we set tagged #pocketlocator on codepen.





Using with other languages

Flash ActionScript3

var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, loadXML);
loader.load(new URLRequest("https://www.pocket-locator.com/api/?k=[your-user-key]&f=xml"));

function loadXML(e:Event):void
{
  var pl:XML = new XML(e.target.data);
}


PHP

<?php
// just to get the address
$myPLAddress = file_get_contents('https://www.pocket-locator.com/api/?k=[your-user-key]&f=txt');
echo $myPLAddress;

// to get full datas
$PL = file_get_contents('https://www.pocket-locator.com/api/?k=[your-user-key]&f=json');
$PL = json_decode($PL);
echo $PL->pocketlocator->label;
?>

See demo


ASP.Net

using System.Text;
using System.Net;
using System.IO;

HttpWebRequest urlRequest = (HttpWebRequest) WebRequest.Create("https://www.pocket-locator.com/api/?k=[your-user-key]&f=txt");
urlRequest.Method = "GET";

WebResponse urlResponse = urlRequest.GetResponse();

StreamReader stream = new StreamReader(urlResponse.GetResponseStream(), System.Text.Encoding.UTF8);
string result = stream.ReadToEnd();
stream.Close();

urlResponse.Close();


RUBY

require 'net/http'
myPLAddress = Net::HTTP.get_response(URI.parse("https://www.pocket-locator.com/api/?k=[your-user-key]&f=txt")).body


NODE.JS

"request" module is needed for this example (and recommended anyway). Use 'npm install request' to get it.

var request = require('request');

// YOUR API KEY
var apikey = "0ea9eb6af06c7278aca52355d60c89ef";

// API URL TO CALL
var url = 'https://www.pocket-locator.com/api/?k='+apikey+'&f=json';

// CALLING OUR API
request.get({
  url: url,
  json: true,
  headers: {'User-Agent': 'nodejs request'}
}, (err, res, data) => {
  if (err) {
    console.log('Error:', err);
  } else if (res.statusCode !== 200) {
    console.log('Status:', res.statusCode);
  } else {
    // data is already parsed as JSON:
    console.log(data.pocketlocator.label);
  }
});


ATOM feed

Atom feed is a cleaner & modern version of RSS format.

Here is how the feed shows in Vienna, an opensource Atom/RSS reader.

Atom feed in Vienna, an opensource RSS/Atom reader


STILL HAVING TROUBLE?

Don't be shy, just contact us