Geolocation API Demo

by Ryan Brackett

HTML

<link rel="stylesheet" href="https://bootswatch.com/flatly/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAWyCb1Xq7gDRWSWRnOAVF3VsBz9TQW-og"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gmaps.js/0.4.24/gmaps.min.js"></script>

<script src="https://cdn.kyruus.com/lib/kyruus-search-widget/version/2/kyruus-search-widget.min.js"></script>

<div id="kyruus-search-widget"></div>

  <button type="button" class="my-location">Find My Location</button>


  <p class="no-browser-support" style="display: none;">Sorry, the Geolocation API isn't supported in Your browser.</p>

JavaScript

//KYRUUS SEARCH WIDGET
(function() {
  var kyruusSearchWidget = new KyruusSearchWidget({
    pm_url: 'https://doctors.nghs.com',
    el: document.getElementById('kyruus-search-widget'),
    customer_code: 'nghs',
    search_label: 'Search',
    message: 'ex: Primary Care',
    show_location: true,
    location_search_radius: 10,
    show_powered_by: false,
    typeahead_categories: [{
        "category": "clinical_experience"
      },
      {
        "category": "specialty_synonym"
      },
      {
        "category": "name"
      },
      {
        "category": "primary_care"
      }
    ],
    allow_empty_search: true,
    focus_on_widget: true,
    use_primary_care_condition: true,
    persist_query: true,
    legal_message: 'off',
    sort_order: 'relevance, networks',
  });
}());

var myLocationButton = $('.my-location');

$(myLocationButton).on('click', function() {

  var zip = "";
  $.ajax({
    url: '//api.ipstack.com/check?access_key=904086e92f6c84548ca40197b0f7c7c8&format=1&security = 1',
    data: {
      format: 'json'
    },
    error: function() {
      $('#info').html('<p>An error has occurred</p>');
    },
    dataType: 'jsonp',
    success: function(data) {

      console.log();

      $("#location").val(data["zip"])
    },
    type: 'GET'
  });


});