Geo - globules-io/OGX.JS GitHub Wiki

OGX.JS comes with a helper object Geo to use when it comes to dealing with Google Maps Javascript API + Places API. It provides a bunch of methods as shortcuts to acquire or transform locations information. To use this component you have to enable Google Maps and Places APIs and add the necessary links to Google resources in your index page.

 <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=_YOUR_KEY_&libraries=places&callback=YOUR_GLOBAL_FUNCTION"></script>

Create

 const geo = OGX.Geo();

to do : document map obj methods

Events

To check if the map is ready to use, do

  $(document).on(OGX.Geo.MAP_LOADED, function(){
       //map ready
  });
  geo.setMap(map);

to do : document other events

Geo Methods

Get distance in km between two locations

 geo.getDistance(__lat0, __lng0, __lat1, __lng1);

Retrieve latitude and longitude given a partial or complete address

 geo.addressToLatLng(
      __address, //String, partial or complete address
      __callback, //Function, return callback
      __params, //Object, optional, optional obj that will be returned in the callback 
 ) 

Retrieve address given location object

 geo.latLngToAddress(
      __loc, //Object, such as {lat:_NUMBER_, lng:_NUMBER_}
      __cb, //Function, return callback
      __params //Object, optional, optional obj that will be returned in the callback 
 );

Retrieve location object given zip/postal code

 geo.zipToLatLng(
      __zip, //String, zip or postal code
      __cb, //Function, return callback
      __params //Object, optional, optional obj that will be returned in the callback 
 );

Convert zip/postal code to address

 geo.zipToAddress(
      __zip, //String, zip or postal code
      __callback, //Function, return callback
      __params, //Object, optional, optional obj that will be returned in the callback  
 );

Retrieve the geo boundaries of a city

geo.getCityBoundaries = function(
      __city, //String, city
      __state, //String, state or province
      __country, //String, usa or canada
      __cb, //Function, return callback
      __params //Object, optional, optional obj that will be returned in the callback 
);

Convert a location object (latitude + longitude) into zip/postal code

 geo.latLngToZip(
      __loc, //Object, such as {lat:_NUMBER_, lng:_NUMBER_}
      __cb, //Function, return callback
      __params //Object, optional, optional obj that will be returned in the callback 
 );

Convert a location object (latitude + longitude) into a country, state, city object

 geo.latLngToCountryStateCity(
      __loc, //Object, such as {lat:_NUMBER_, lng:_NUMBER_}
      __cb, //Function, return callback
      __params //Object, optional, optional obj that will be returned in the callback 
 );

Attempt to convert a partial address into a country, state, city object

 geo.partialAddressToCountryStateCity(
      __address, //String, partial or complete address
      __callback, //Function, return callback
      __params, //Object, optional, optional obj that will be returned in the callback 
 );

The returned object to the callback is an object with the following format

 {country:_2_letter_code_, state:_string_, city:_string_, zip:_string_, number:_string_, lat:_number_, lng:_number_}

To clean an address object and keep certain properties only (city, state in this example), do

 let address = geo.clean(address, ['city', 'state']);
⚠️ **GitHub.com Fallback** ⚠️