Google and Baidu latitude and longitude Mutual transfer (Plsql version)

Source: Internet
Author: User
Tags acos cos sin

Create two stored procedures first

Baidu2google (Baidu to Google) and Google2baidu (Google to Baidu).

CREATE OR REPLACE PROCEDURE "Baidu2google"
(In_lat in Out number,in_lng on out number)
Is
RESULT number;
V number;
X number;
Y number;
Z number;
T number;
BEGIN

    IF In_lat is null OR in_lng are null then
       RETURN;
    END IF;
   
    IF in_lat = 0 OR in_lng = 0 Then
       RE TURN;
    END IF;
   
    V: = (ACOS ( -1) * 3000.0)/180.0;
    X: = in_lng-0.0065;
    Y: = in_lat-0.006;
   
    IF X = 0 OR Y = 0 Then
      RETURN;
    END IF;
   
    Z: = sqrt (x*x + y*y)-0.00002 * sin (y*v);
    T: = atan2 (y,x)-0.000003 * cos (X*V);

In_lat: = Z * sin (T);
IN_LNG: = Z * cos (T);

EXCEPTION
When OTHERS Then
NULL;
END;


CREATE OR REPLACE PROCEDURE "Google2baidu"
(In_lat in Out number,in_lng on out number)
Is
RESULT number;
V number;
X number;
Y number;
Z number;
T number;
BEGIN

IF In_lat is null OR IN_LNG was null then
RETURN;
END IF;

IF In_lat = 0 OR in_lng = 0 Then
RETURN;
END IF;

V: = (ACOS (-1) * 3000.0)/180.0;
X: = IN_LNG;
Y: = In_lat;
Z: = sqrt (x*x + y*y) + 0.00002 * sin (y*v);
T: = atan2 (y,x) + 0.000003 * cos (X*V);

In_lat: = Z * sin (T) + 0.006;
IN_LNG: = Z * cos (T) + 0.0065;

EXCEPTION
When OTHERS Then
NULL;
END;


Test code:

Declare
Val varchar2 (1024);
Lat number;
LNG number;
Begin
Lat: = 25.123456;
LNG: = 120.987654;

Google2baidu (LAT,LNG);
Val: = To_char (lat) | | ', ' | | To_char (LNG);
Dbms_output.put_line (Val);
Baidu2google (LAT,LNG);
Val: = To_char (lat) | | ', ' | | To_char (LNG);
Dbms_output.put_line (Val);
End


Output Result:

25.12950357111129114394070387150607218949, 120.99415968477080269592699287102653898
25.12345611379500842252418931941721965068, 120.987654009372443376128478150908972217

Google and Baidu latitude and longitude Mutual transfer (Plsql version)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.