Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 851775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:29:01+00:00 2026-05-15T07:29:01+00:00

i’m trying to built in support for locations in my application and i’m expecting

  • 0

i’m trying to built in support for locations in my application and i’m expecting users to be inputting gps coordinates in a variety of ways. I need to convert all of the below to: latitude – direction (N/s), degres, minutes, seconds; longitude (E/W) – degrees, minuts, seconds.

Note, each user input will be in a single line. I would like my users to input only in one single way, but ppl will definitely enter as one of the following…:

eg:
9.182, -39.140625
9.182 / -39.140625
9.182,-39.140625
9.182 -39.140625
21° 16′ 674S[some_separator]27° 30′ 318E
21 16 674S[some_separator]27 30 318E

[some_separator] may be a single space as well…

The final format needs to beas:
latitude.direction = south
latitude.degrees = 21
latitude.minutes = 16
latitude.seconds = 674
longitude.direction = east
longitude.degrees = 27
longitude.minutes = 30
longitude.seconds = 318

(a) what is the simplest way of asking ordinary-non-tech users to input the GPS coordinate?s
(b) how do i convert the above to the final format? any built in functions that handle these variations in data input?

i’ve seen GPS format in PHP – but i need to handle a more varied input.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T07:29:02+00:00Added an answer on May 15, 2026 at 7:29 am

    I have been working around with this further (and I notice that you edited your question).

    A) What is the simplest way of asking ordinary-non-tech users to input the GPS coordinates?

    The simplest, and most user friendly fashion for getting non-tech users to enter details would be using Google Maps. This would allow for you to use the Google Geocoder to parse their input (and provide a more standardised and formatted output). Further, if the location the user is inputting is their current location, you could look at using the Geolocation functionality offered by some of the modern browsers.

    B) How do i convert the above to the final format? Any built in functions that handle these variations in data input?

    Based on your test data, I have formulated a PHP Regular Expression to parse it and return a predictable and standardised output.

    $rexp = '/^(\-?\d+(?:\.\d+)?)(?:\D+(\d+)\D+(\d+)([NS]?))?[^\d\-]+(\-?\d+(?:\.\d+)?)(?:\D+(\d+)\D+(\d+)([EW]?))?$/i';
    
    $data = array(
      "21° 16' 674S, 27° 30' 318E" ,
      '21 16 674S, 27 30 318E' ,
      '9.182, -39.140625' ,
      '9.182 / -39.140625' ,
      '9.182,-39.140625' ,
      '9.182 -39.140625'
    );
    
    foreach( $data as $test ) {
      if( !preg_match( $rexp , $test , $matches ) ) {
        echo '<b>Failed</b>';
      } else {
        // Match Found
      }
    }
    

    Outputs:

    array(
      [0] => Matched Text ,
      [1] => Full Degrees ,
      [2] => Minutes ,
      [3] => Seconds ,
      [4] => Hemisphere (N or S) ,
      [5] => Full Degrees ,
      [6] => Minutes ,
      [7] => Seconds ,
      [8] => Hemisphere (E or W)
    )
    

    Example:

    // Matching 21° 16' 674S, 27° 30' 318E
    array(
      [0] => "21° 16' 674S, 27° 30' 318E" ,
      [1] => "21" , [2] => "16" , [3] => "674" , [4] => "S" ,
      [5] => "27" , [6] => "30" , [7] => "318" , [8] => "E"
    )
    
    // Matching 21 16 674S, 27 30 318E
    array(
      [0]=> "21 16 674S, 27 30 318E" ,
      [1]=> "21" , [2]=> "16" , [3]=> "674" , [4]=> "S" ,
      [5]=> "27" , [6]=> "30" , [7]=> "318" , [8]=> "E"
    )
    
    // Matching 9.182, -39.140625
    array(
      [0]=> "9.182, -39.140625" ,
      [1]=>   "9.182" ,    [2]=> "" , [3]=> "" , [4]=> "" ,
      [5]=> "-39.140625" , [6]=> "" , [7]=> "" , [8]=> ""
    )
    
    // Matching 9.182 / -39.140625
    array(
      [0]=> "9.182 / -39.140625" ,
      [1]=>   "9.182" ,    [2]=> "" , [3]=> "" , [4]=> "" ,
      [5]=> "-39.140625" , [6]=> "" , [7]=> "" , [8]=> ""
    )
    
    // Matching 9.182,-39.140625
    array(
      [0]=> "9.182,-39.140625" ,
      [1]=>   "9.182" ,    [2]=> "" , [3]=> "" , [4]=> "" ,
      [5]=> "-39.140625" , [6]=> "" , [7]=> "" , [8]=> ""
    )
    
    // Matching 9.182 -39.140625
    array(
      [0]=> "9.182 -39.140625" ,
      [1]=>   "9.182" ,    [2]=> "" , [3]=> "" , [4]=> "" ,
      [5]=> "-39.140625" , [6]=> "" , [7]=> "" , [8]=> ""
    )
    

    You could then, subsequently, process the results of the Regular Expression, to produce a float for the Lat/Long link so:

    // (Replacing the "Match Found" comment)
      $latitude  = $matches[1]+((int)$matches[2]/60)+((int)$matches[3]/3600)*(strtolower($matches[4])=='s'?-1:1);
      $longitude = $matches[5]+((int)$matches[6]/60)+((int)$matches[7]/3600)*(strtolower($matches[8])=='w'?-1:1);
    

    Which produces:

    // Matching 21° 16' 674S, 27° 30' 318E
    $latitude  = -21.4538888889
    $longitude =  27.5883333333
    
    // Matching 21 16 674S, 27 30 318E
    $latitude  = -21.4538888889
    $longitude =  27.5883333333
    
    // Matching 9.182, -39.140625
    $latitude  =   9.182
    $longitude = -39.140625
    
    // Matching 9.182 / -39.140625
    $latitude  =   9.182
    $longitude = -39.140625
    
    // Matching 9.182,-39.140625
    $latitude  =   9.182
    $longitude = -39.140625
    
    // Matching 9.182 -39.140625
    $latitude  =   9.182
    $longitude = -39.140625
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.