0

I tried to store GPS latitude and longitude value in DMS format with the degree and apostrophe in mysql with php.

The previous solution is convert it into Decimal.

Is there any particular datatype to store the value in mysql with the symbols like below:

12°53′17″N
80°13′52″E

The proble is,it replaces with 12°53′17″ N, 80°13′52″ E.

Mark Reed
  • 91,912
  • 16
  • 138
  • 175
m2j
  • 1,152
  • 5
  • 18
  • 43
  • 2
    In that exact format? It would have to be a string type like `nvarchar()`. But most commonly latitude and longitude are stored as decimals, as you said is already the case. – Tyler Roper Mar 23 '17 at 17:06
  • thanks.. but it doesn't help me.. – m2j Mar 23 '17 at 17:13
  • @m2j, it probably doesn't do that, it's just that you haven't figured out how text encoding / character sets work. – Evert Mar 23 '17 at 17:19
  • @m2j *"Is there any particular datatype to store the value in mysql with the symbols like below"*. I answered the question you asked. If it isn't helpful, ask a different question. – Tyler Roper Mar 23 '17 at 17:22
  • if you format lil bit like instead of `′` use single quot `'` then you can store like this `12°53'17''N` – BetaDev Mar 23 '17 at 17:33
  • Possible duplicate of [MySQL or PHP is appending a  whenever the £ is used](http://stackoverflow.com/questions/386378/mysql-or-php-is-appending-a-%c3%82-whenever-the-%c2%a3-is-used) – Mark Reed Mar 23 '17 at 17:47

1 Answers1

1

Create your table by setting the character set as utf-UTF-8 Unicode. If you specify the Character set for the table as Unicode then it will accept the original latitude/longitude Values. Reference code for SQL:

ALTER TABLE `gps`
DEFAULT CHARACTER SET=utf8;

The following works for me

CREATE TABLE `gps` (
  `lat` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
BetaDev
  • 4,516
  • 3
  • 21
  • 47
  • 1
    using php there are lots of way, replace the `′` with single quotation `'`, or use string escaping by inserting back slash `\` for `′` and `″`, remember these are not single quot and double quot. using PHP we can replace any string in between three values and explode then at the time of operation and then convert them in decimal too. – BetaDev Mar 23 '17 at 18:29