ÿþ/ *  
 *   c o n v e r t   l a t / l o n g   i n   d e g r e e s   t o   r a d i a n s ,   f o r   h a n d l i n g   i n p u t   v a l u e s  
 *  
 *       t h i s   i s   v e r y   f l e x i b l e   o n   f o r m a t s ,   a l l o w i n g   s i g n e d   d e c i m a l   d e g r e e s   ( n u m e r i c   o r   t e x t ) ,   o r  
 *       d e g - m i n - s e c   s u f f i x e d   b y   c o m p a s s   d i r e c t i o n   ( N S E W ) .   A   v a r i e t y   o f   s e p a r a t o r s   a r e   a c c e p t e d    
 *       ( e g   3 º   3 7 '   0 9 " W )   o r   f i x e d - w i d t h   f o r m a t   w i t h o u t   s e p a r a t o r s   ( e g   0 0 3 3 7 0 9 W ) .   S e c o n d s   a n d   m i n u t e s  
 *       m a y   b e   o m i t t e d .   M i n i m a l   v a l i d a t i o n   i s   d o n e .  
 * /  
 L a t L o n g . l l T o R a d   =   f u n c t i o n   ( b r n g )   {  
         i f   ( ! i s N a N ( b r n g ) )   r e t u r n   b r n g   *   M a t h . P I   /   1 8 0 ;     / /   s i g n e d   d e c i m a l   d e g r e e s   w i t h o u t   N S E W  
  
         b r n g   =   b r n g . r e p l a c e ( / [ \ s ] * $ / ,   ' ' ) ;                               / /   s t r i p   t r a i l i n g   w h i t e s p a c e  
         v a r   d i r   =   b r n g . s l i c e ( - 1 ) . t o U p p e r C a s e ( ) ;                   / /   c o m p a s s   d i r ' n  
         i f   ( ! / [ N S E W ] / . t e s t ( d i r ) )   r e t u r n   N a N ;                         / /   c h e c k   f o r   c o r r e c t   c o m p a s s   d i r e c t i o n  
         b r n g   =   b r n g . s l i c e ( 0 ,   - 1 ) ;                                                 / /   a n d   l o s e   i t   o f f   t h e   e n d  
         v a r   d m s   =   b r n g . s p l i t ( / [ \ s : , ° º 2 \ ' 3 \ " ] / )                     / /   c h e c k   f o r   s e p a r a t o r s   i n d i c a t i n g   d / m / s  
         s w i t c h   ( d m s . l e n g t h )   {                                                       / /   c o n v e r t   t o   d e c i m a l   d e g r e e s . . .  
                 c a s e   3 :                                                                               / /   i n t e r p r e t   3 - p a r t   r e s u l t   a s   d / m / s  
                         v a r   d e g   =   d m s [ 0 ]   /   1   +   d m s [ 1 ]   /   6 0   +   d m s [ 2 ]   /   3 6 0 0 ;   b r e a k ;  
                 c a s e   2 :                                                                               / /   i n t e r p r e t   2 - p a r t   r e s u l t   a s   d / m  
                         v a r   d e g   =   d m s [ 0 ]   /   1   +   d m s [ 1 ]   /   6 0 ;   b r e a k ;  
                 c a s e   1 :                                                                               / /   n o n - s e p a r a t e d   f o r m a t   d d d m m s s  
                         i f   ( / [ N S ] / . t e s t ( d i r ) )   b r n g   =   ' 0 '   +   b r n g ;         / /   -   n o r m a l i s e   N / S   t o   3 - d i g i t   d e g r e e s  
                         v a r   d e g   =   b r n g . s l i c e ( 0 ,   3 )   /   1   +   b r n g . s l i c e ( 3 ,   5 )   /   6 0   +   b r n g . s l i c e ( 5 )   /   3 6 0 0 ;   b r e a k ;  
                 d e f a u l t :   r e t u r n   N a N ;  
         }  
         i f   ( / [ W S ] / . t e s t ( d i r ) )   d e g   =   - d e g ;                               / /   t a k e   w e s t   a n d   s o u t h   a s   - v e  
         r e t u r n   d e g   *   M a t h . P I   /   1 8 0 ;                                           / /   t h e n   c o n v e r t   t o   r a d i a n s  
 }  
  
  
  
 / *  
 *   L a t L o n g   c o n s t r u c t o r :  
 * /  
 f u n c t i o n   L a t L o n g ( d e g L a t ,   d e g L o n g )   {  
         t h i s . l a t   =   L a t L o n g . l l T o R a d ( d e g L a t ) ;  
         t h i s . l o n   =   L a t L o n g . l l T o R a d ( d e g L o n g ) ;  
 }  
  
  
 / *  
 *   C a l c u l a t e   d i s t a n c e   ( i n   k m )   b e t w e e n   t w o   p o i n t s   s p e c i f i e d   b y   l a t i t u d e / l o n g i t u d e   w i t h   H a v e r s i n e   f o r m u l a  
 *  
 * /  
 f u n c t i o n   d i s t a n c e b e t w e e n ( p 1 ,   p 2 )   {  
         v a r   R   =   6 3 7 1 ;   / /   e a r t h ' s   m e a n   r a d i u s   i n   k m  
         v a r   d L a t   =   p 2 . l a t   -   p 1 . l a t ;  
         v a r   d L o n g   =   p 2 . l o n   -   p 1 . l o n ;  
  
         v a r   a   =   M a t h . s i n ( d L a t   /   2 )   *   M a t h . s i n ( d L a t   /   2 )   +  
                     M a t h . c o s ( p 1 . l a t )   *   M a t h . c o s ( p 2 . l a t )   *   M a t h . s i n ( d L o n g   /   2 )   *   M a t h . s i n ( d L o n g   /   2 ) ;  
         v a r   c   =   2   *   M a t h . a t a n 2 ( M a t h . s q r t ( a ) ,   M a t h . s q r t ( 1   -   a ) ) ;  
         v a r   d   =   R   *   c ;  
  
         r e t u r n   d ;  
 }  
  
  
 v a r   m a p ;                 / /   a d d e d    
  
 f u n c t i o n   c r e a t e M a p N o M a r k e r s ( d b l L a t i t u d e ,   d b l L o n g i t u d e ,   l n g Z o o m ,   d l a t ,   d l o n g )   {  
         / /   c r e a t e s   a   m a p   w i t h   n o   m a r k e r s    
         i f   ( G B r o w s e r I s C o m p a t i b l e ( ) )   {  
                 m a p   =   n e w   G M a p 2 ( d o c u m e n t . g e t E l e m e n t B y I d ( " m a p " ) ) ;  
                 m a p . a d d C o n t r o l ( n e w   G S m a l l M a p C o n t r o l ( ) ) ;  
                 m a p . a d d C o n t r o l ( n e w   G M a p T y p e C o n t r o l ( ) ) ;  
                 m a p . a d d C o n t r o l ( n e w   G S c a l e C o n t r o l ( ) ) ;  
                 m a p . s e t C e n t e r ( n e w   G L a t L n g ( d b l L a t i t u d e ,   d b l L o n g i t u d e ) ,   l n g Z o o m ) ;  
                 v a r   h p o s   =   n e w   L a t L o n g ( d l a t ,   d l o n g )  
         }  
         e l s e   {  
                 a l e r t ( " S o r r y ,   y o u r   b r o w s e r   i s   n o t   c o m p a t i b l e " )  
         }  
 }  
  
 / /   C r e a t e s   a   m a r k e r   a t   t h e   g i v e n   p o i n t   w i t h   t h e   g i v e n   n u m b e r   l a b e l  
 f u n c t i o n   c r e a t e M a r k e r ( p o i n t ,   t e x t ,   l a t ,   l n g ,   d l a t ,   d l o n g )   {  
         v a r   m a r k e r   =   n e w   G M a r k e r ( p o i n t ) ;  
         G E v e n t . a d d L i s t e n e r ( m a r k e r ,   " c l i c k " ,   f u n c t i o n   ( )   {  
                 v a r   t h i s p o s   =   n e w   L a t L o n g ( l a t ,   l n g )  
                 v a r   h p o s   =   n e w   L a t L o n g ( d l a t ,   d l o n g )  
                 v a r   d b   =   d i s t a n c e b e t w e e n ( t h i s p o s ,   h p o s )  
                 v a r   d b m i l e s   =   d b   *   0 . 6 2 1 3 7 1 1 9 2  
                 v a r   k m   =   M a t h . r o u n d ( d b   *   1 0 )   /   1 0  
                 v a r   m i l e s   =   M a t h . r o u n d ( d b m i l e s   *   1 0 )   /   1 0  
                 d o c u m e n t . g e t E l e m e n t B y I d ( " H M o u s e P o s " ) . i n n e r H T M L   =   t e x t  
                 i f   ( d b   >   0 )   {  
                         / / d o c u m e n t . g e t E l e m e n t B y I d ( " M o u s e P o s " ) . i n n e r H T M L + =   "   ( "   +   m i l e s   +   "   m i / "   +   k m   +   "   k m   f r o m   p r o p e r t y ) "  
                 }  
         } ) ;  
         G E v e n t . a d d L i s t e n e r ( m a r k e r ,   " m o u s e o v e r " ,   f u n c t i o n   ( )   {  
                 v a r   t h i s p o s   =   n e w   L a t L o n g ( l a t ,   l n g )  
                 v a r   h p o s   =   n e w   L a t L o n g ( d l a t ,   d l o n g )  
                 v a r   d b   =   d i s t a n c e b e t w e e n ( t h i s p o s ,   h p o s )  
                 v a r   d b m i l e s   =   d b   *   0 . 6 2 1 3 7 1 1 9 2  
                 v a r   k m   =   M a t h . r o u n d ( d b   *   1 0 )   /   1 0  
                 v a r   m i l e s   =   M a t h . r o u n d ( d b m i l e s   *   1 0 )   /   1 0  
                 d o c u m e n t . g e t E l e m e n t B y I d ( " H M o u s e P o s " ) . i n n e r H T M L   =   t e x t  
                 i f   ( d b   >   0 )   {  
                         / / d o c u m e n t . g e t E l e m e n t B y I d ( " M o u s e P o s " ) . i n n e r H T M L + =   "   ( "   +   m i l e s   +   "   m i / "   +   k m   +   "   k m   f r o m   p r o p e r t y ) "  
                 }  
         } ) ;  
         G E v e n t . a d d L i s t e n e r ( m a r k e r ,   " m o u s e o u t " ,   f u n c t i o n   ( )   {  
                 d o c u m e n t . g e t E l e m e n t B y I d ( " H M o u s e P o s " ) . i n n e r H T M L   =   d e s t  
         } ) ;  
         r e t u r n   m a r k e r ;  
 }  
  
  
 f u n c t i o n   c r e a t e M a i n M a r k e r ( d b l L a t i t u d e ,   d b l L o n g i t u d e )   {  
         / /   c r e a t e s   a   m a r k e r   o n   a   p r e v i o u s l y   c r e a t e d   m a p    
         v a r   p o i n t   =   n e w   G L a t L n g ( d b l L a t i t u d e ,   d b l L o n g i t u d e ) ;  
         m a p . a d d O v e r l a y ( c r e a t e M a r k e r ( p o i n t ,   " " ,   d b l L a t i t u d e ,   d b l L o n g i t u d e ) ) ;  
 }  
  
 f u n c t i o n   l a n d m a r k ( d l a t ,   d l o n g )   {  
         v a r   s e l   =   d o c u m e n t . g e t E l e m e n t B y I d ( " l a n d m a r k s " )  
         v a r   l m a r k   =   s e l . o p t i o n s [ s e l . s e l e c t e d I n d e x ] . v a l u e  
  
         i f   ( l m a r k   ! =   " " )   {  
                 v a r   l s p l i t   =   l m a r k . s p l i t ( " | " )  
                 v a r   c o   =   l s p l i t [ 1 ]  
                 v a r   c s p l i t   =   c o . s p l i t ( " , " )  
                 c r e a t e N e w M a r k e r ( c s p l i t [ 0 ] ,   c s p l i t [ 1 ] ,   l s p l i t [ 0 ] ,   d l a t ,   d l o n g )  
                 / / d o c u m e n t . g e t E l e m e n t B y I d ( " H M o u s e P o s " ) . i n n e r H T M L = " L a n d m a r k   l o c a t e d   -   h o v e r   o r   c l i c k   t o   s e e   d i s t a n c e   f r o m   p r o p e r t y "  
         }  
 }  
  
 f u n c t i o n   c r e a t e N e w M a r k e r ( d b l L a t i t u d e ,   d b l L o n g i t u d e ,   t i t l e ,   d l a t ,   d l o n g )   {  
         / /   c r e a t e s   a   m a r k e r   o n   a   p r e v i o u s l y   c r e a t e d   m a p    
         v a r   p o i n t   =   n e w   G L a t L n g ( d b l L a t i t u d e ,   d b l L o n g i t u d e ) ;  
         m a p . a d d O v e r l a y ( c r e a t e M a r k e r ( p o i n t ,   t i t l e ,   d b l L a t i t u d e ,   d b l L o n g i t u d e ,   d l a t ,   d l o n g ) ) ;  
         m a p . s e t C e n t e r ( p o i n t ,   1 4 ) ;  
  
 }  
 
