haversine-distance-in-kms
v1.0.1
Published
A simple package to calculate haversine distance and find the closest driver to a pickup location.
Downloads
9
Maintainers
Readme
��#�#� �h�a�v�e�r�s�i�n�e�-�d�i�s�t�a�n�c�e�-�i�n�-�k�m�s�
�
�
�
���A� �l�i�g�h�t�w�e�i�g�h�t� �N�o�d�e�.�j�s� �p�a�c�k�a�g�e� �f�o�r� �c�a�l�c�u�l�a�t�i�n�g� �t�h�e� �H�a�v�e�r�s�i�n�e� �d�i�s�t�a�n�c�e� �b�e�t�w�e�e�n� �g�e�o�g�r�a�p�h�i�c�a�l� �c�o�o�r�d�i�n�a�t�e�s� �a�n�d� �f�i�n�d�i�n�g� �t�h�e� �c�l�o�s�e�s�t� �d�r�i�v�e�r� �f�r�o�m� �a� �l�i�s�t�.���
�
�
�
�#�#�#� �I�n�s�t�a�l�l�a�t�i�o�n�
�
�
�
�B�a�s�h�
�
�
�
��
��
�
�n�p�m� �i�n�s�t�a�l�l� �h�a�v�e�r�s�i�n�e�-�d�i�s�t�a�n�c�e�-�i�n�-�k�m�s�
�
�
�
�
��
�
�
�
�
�U�s�e� �c�o�d�e� �[�w�i�t�h� �c�a�u�t�i�o�n�.�]�(�/�f�a�q�#�c�o�d�i�n�g�)�
�
�
�
�#�#�#� �U�s�a�g�e�
�
�
�
���1�.� �C�a�l�c�u�l�a�t�i�n�g� �H�a�v�e�r�s�i�n�e� �D�i�s�t�a�n�c�e���
�
�
�
�T�h�e� �p�a�c�k�a�g�e� �o�f�f�e�r�s� �t�w�o� �w�a�y�s� �t�o� �c�a�l�c�u�l�a�t�e� �t�h�e� �H�a�v�e�r�s�i�n�e� �d�i�s�t�a�n�c�e�:�
�
�
�
�-� ����h�a�v�e�r�s�i�n�e�D�i�s�t�a�n�c�e�(�l�a�t�1�,� �l�o�n�1�,� �l�a�t�2�,� �l�o�n�2�)�
� �f�u�n�c�t�i�o�n�:��� �A�c�c�e�p�t�s� �f�o�u�r� �p�a�r�a�m�e�t�e�r�s� �r�e�p�r�e�s�e�n�t�i�n�g� �t�h�e� �l�a�t�i�t�u�d�e�s� �a�n�d� �l�o�n�g�i�t�u�d�e�s� �o�f� �t�h�e� �t�w�o� �p�o�i�n�t�s�.�
�
�
�
�J�a�v�a�S�c�r�i�p�t�
�
�
�
��
��
�
�c�o�n�s�t� �d�i�s�t�a�n�c�e�_�1� �=� �h�a�v�e�r�s�i�n�e�D�i�s�t�a�n�c�e�(�1�3�.�0�3�4�7�7�,� �8�0�.�1�5�6�1�5�,� �1�2�.�9�7�1�5�9�8�7�,� �7�7�.�5�9�4�5�6�2�7�)�;�
�
�c�o�n�s�o�l�e�.�l�o�g�(�d�i�s�t�a�n�c�e�_�1�)�;� �/�/� �O�u�t�p�u�t� �i�n� �k�i�l�o�m�e�t�e�r�s� �(�k�m�)�
�
�
�
�
��
�
�
�
�
�U�s�e� �c�o�d�e� �[�w�i�t�h� �c�a�u�t�i�o�n�.�]�(�/�f�a�q�#�c�o�d�i�n�g�)�
�
�
�
�-� ����h�a�v�e�r�s�i�n�e�D�i�s�t�a�n�c�e�O�b�j�(�p�o�i�n�t�1�,� �p�o�i�n�t�2�)�
� �f�u�n�c�t�i�o�n�:��� �A�c�c�e�p�t�s� �t�w�o� �o�b�j�e�c�t�s� �w�i�t�h� ��l�a�t�
� �a�n�d� ��l�o�n�
� �p�r�o�p�e�r�t�i�e�s� �r�e�p�r�e�s�e�n�t�i�n�g� �t�h�e� �c�o�o�r�d�i�n�a�t�e�s�.�
�
�
�
�J�a�v�a�S�c�r�i�p�t�
�
�
�
��
��
�
�c�o�n�s�t� �d�i�s�t�a�n�c�e� �=� �h�a�v�e�r�s�i�n�e�D�i�s�t�a�n�c�e�O�b�j�(�{� �l�a�t�:� �1�3�.�0�3�4�7�7�,� �l�o�n�:� �8�0�.�1�5�6�1�5� �}�,� �{� �l�a�t�:� �1�2�.�9�7�1�5�9�8�7�,� �l�o�n�:� �7�7�.�5�9�4�5�6�2�7� �}�)�;�
�
�c�o�n�s�o�l�e�.�l�o�g�(�d�i�s�t�a�n�c�e�)�;� �/�/� �O�u�t�p�u�t� �i�n� �k�i�l�o�m�e�t�e�r�s� �(�k�m�)�
�
�
�
�
��
�
�
�
�
�U�s�e� �c�o�d�e� �[�w�i�t�h� �c�a�u�t�i�o�n�.�]�(�/�f�a�q�#�c�o�d�i�n�g�)�
�
�
�
���2�.� �F�i�n�d�i�n�g� �t�h�e� �C�l�o�s�e�s�t� �D�r�i�v�e�r���
�
�
�
�T�h�e� ��f�i�n�d�C�l�o�s�e�s�t�D�r�i�v�e�r�(�d�r�i�v�e�r�s�,� �f�r�o�m�L�a�t�,� �f�r�o�m�L�o�n�)�
� �f�u�n�c�t�i�o�n� �i�d�e�n�t�i�f�i�e�s� �t�h�e� �c�l�o�s�e�s�t� �a�v�a�i�l�a�b�l�e� �d�r�i�v�e�r� �f�r�o�m� �a� �l�i�s�t� �o�f� �d�r�i�v�e�r�s� �w�i�t�h� �t�h�e�i�r� �c�o�o�r�d�i�n�a�t�e�s� �a�n�d� �a�v�a�i�l�a�b�i�l�i�t�y� �s�t�a�t�u�s�.�
�
�
�
�J�a�v�a�S�c�r�i�p�t�
�
�
�
��
��
�
�c�o�n�s�t� �d�r�i�v�e�r�s� �=� �[�
�
� � �{� �i�d�:� �1�,� �n�a�m�e�:� �"�P�e�r�s�o�n� �A�"�,� �l�a�t�:� �1�2�.�9�7�1�5�9�8�7�,� �l�o�n�:� �7�7�.�5�9�4�5�6�2�7�,� �a�v�a�i�l�a�b�l�e�:� �t�r�u�e� �}�,�
�
� � �{� �i�d�:� �2�,� �n�a�m�e�:� �"�P�e�r�s�o�n� �B�"�,� �l�a�t�:� �1�3�.�0�8�2�6�8�0�2�,� �l�o�n�:� �8�0�.�2�7�0�7�1�8�4�,� �a�v�a�i�l�a�b�l�e�:� �t�r�u�e� �}�,�
�
� � �{� �i�d�:� �3�,� �n�a�m�e�:� �"�P�e�r�s�o�n� �C�"�,� �l�a�t�:� �1�2�.�2�9�5�8�1�0�4�,� �l�o�n�:� �7�6�.�6�3�9�3�8�0�5�,� �a�v�a�i�l�a�b�l�e�:� �t�r�u�e� �}�,�
�
� � �{� �i�d�:� �4�,� �n�a�m�e�:� �"�P�e�r�s�o�n� �D�"�,� �l�a�t�:� �1�5�.�3�1�7�2�7�7�5�,� �l�o�n�:� �7�5�.�7�1�3�8�8�8�4�,� �a�v�a�i�l�a�b�l�e�:� �f�a�l�s�e� �}� �/�/� �U�n�a�v�a�i�l�a�b�l�e�
�
�]�;�
�
�c�o�n�s�t� �f�r�o�m�L�a�t� �=� �1�3�.�0�3�4�7�7�;�
�
�c�o�n�s�t� �f�r�o�m�L�o�n� �=� �8�0�.�1�5�6�1�5�;�
�
�
�
�c�o�n�s�t� �c�l�o�s�e�s�t�D�r�i�v�e�r� �=� �f�i�n�d�C�l�o�s�e�s�t�D�r�i�v�e�r�(�d�r�i�v�e�r�s�,� �f�r�o�m�L�a�t�,� �f�r�o�m�L�o�n�)�;�
�
�
�
�i�f� �(�c�l�o�s�e�s�t�D�r�i�v�e�r�)� �{�
�
� � �c�o�n�s�o�l�e�.�l�o�g�(�
�C�l�o�s�e�s�t� �d�r�i�v�e�r�:� �$�{�c�l�o�s�e�s�t�D�r�i�v�e�r�.�n�a�m�e�}�,� �D�i�s�t�a�n�c�e�:� �$�{�c�l�o�s�e�s�t�D�r�i�v�e�r�.�d�i�s�t�a�n�c�e�.�t�o�F�i�x�e�d�(�2�)�}� �k�m��)�;�
�
�}� �e�l�s�e� �{�
�
� � �c�o�n�s�o�l�e�.�l�o�g�(�"�N�o� �d�r�i�v�e�r�s� �a�v�a�i�l�a�b�l�e�.�"�)�;�
�
�}�
�
�
�
�
��
�
�
�
�
�U�s�e� �c�o�d�e� �[�w�i�t�h� �c�a�u�t�i�o�n�.�]�(�/�f�a�q�#�c�o�d�i�n�g�)�
�
�
�
���E�x�p�l�a�n�a�t�i�o�n�:���
�
�
�
�-� �T�h�e� �f�u�n�c�t�i�o�n� �i�t�e�r�a�t�e�s� �t�h�r�o�u�g�h� �t�h�e� ��d�r�i�v�e�r�s�
� �a�r�r�a�y�.�
�
�-� �I�t� �c�a�l�c�u�l�a�t�e�s� �t�h�e� �H�a�v�e�r�s�i�n�e� �d�i�s�t�a�n�c�e� �b�e�t�w�e�e�n� �t�h�e� �p�r�o�v�i�d�e�d� �c�o�o�r�d�i�n�a�t�e�s� �(��f�r�o�m�L�a�t�
�,� ��f�r�o�m�L�o�n�
�)� �a�n�d� �e�a�c�h� �d�r�i�v�e�r�'�s� �c�o�o�r�d�i�n�a�t�e�s�.�
�
�-� �I�t� �k�e�e�p�s� �t�r�a�c�k� �o�f� �t�h�e� �d�r�i�v�e�r� �w�i�t�h� �t�h�e� �s�h�o�r�t�e�s�t� �d�i�s�t�a�n�c�e� �a�n�d� �o�n�l�y� �c�o�n�s�i�d�e�r�s� �a�v�a�i�l�a�b�l�e� �d�r�i�v�e�r�s� �(��a�v�a�i�l�a�b�l�e�:� �t�r�u�e�
�)�.�
�
�-� �I�f� �a� �c�l�o�s�e�s�t� �d�r�i�v�e�r� �i�s� �f�o�u�n�d�,� �i�t� �r�e�t�u�r�n�s� �a�n� �o�b�j�e�c�t� �c�o�n�t�a�i�n�i�n�g� �t�h�e� �d�r�i�v�e�r�'�s� �d�e�t�a�i�l�s� �(�I�D�,� �n�a�m�e�,� �c�o�o�r�d�i�n�a�t�e�s�,� �d�i�s�t�a�n�c�e�)�.�
�
�-� �I�f� �n�o� �a�v�a�i�l�a�b�l�e� �d�r�i�v�e�r�s� �a�r�e� �f�o�u�n�d� �w�i�t�h�i�n� �t�h�e� �l�i�s�t�,� �i�t� �r�e�t�u�r�n�s� ��n�u�l�l�
�.�
�
�
�
���C�o�n�t�r�i�b�u�t�i�n�g���
�
�
�
�W�e� �w�e�l�c�o�m�e� �c�o�n�t�r�i�b�u�t�i�o�n�s� �t�o� �i�m�p�r�o�v�e� �t�h�i�s� �p�a�c�k�a�g�e�.� �F�e�e�l� �f�r�e�e� �t�o� �s�u�b�m�i�t� �p�u�l�l� �r�e�q�u�e�s�t�s� �f�o�r� �b�u�g� �f�i�x�e�s� �o�r� �n�e�w� �f�e�a�t�u�r�e�s�!�
�
�
�
���L�i�c�e�n�s�e���
�
�
�
�T�h�i�s� �p�r�o�j�e�c�t� �i�s� �l�i�c�e�n�s�e�d� �u�n�d�e�r� �t�h�e� �M�I�T� �L�i�c�e�n�s�e�.� �S�e�e� �t�h�e� ��L�I�C�E�N�S�E�
� �f�i�l�e� �f�o�r� �d�e�t�a�i�l�s�.�
�
�
�
���A�d�d�i�t�i�o�n�a�l� �N�o�t�e�s���
�
�
�
�-� �T�h�i�s� �p�a�c�k�a�g�e� �p�r�o�v�i�d�e�s� �b�a�s�i�c� �f�u�n�c�t�i�o�n�a�l�i�t�y� �f�o�r� �c�a�l�c�u�l�a�t�i�n�g� �d�i�s�t�a�n�c�e�s� �a�n�d� �f�i�n�d�i�n�g� �c�l�o�s�e�s�t� �d�r�i�v�e�r�s�.� �Y�o�u� �c�a�n� �c�u�s�t�o�m�i�z�e� �i�t� �f�u�r�t�h�e�r� �t�o� �f�i�t� �y�o�u�r� �s�p�e�c�i�f�i�c� �a�p�p�l�i�c�a�t�i�o�n� �n�e�e�d�s�.�
�
�