Key code:
usingSystem;usingSystem.Collections;usingSystem.Collections.Generic;usingSystem.IO;usingYanZhiwei.DotNet2.Utilities.Models;namespaceyanzhiwei.dotnet2.utilities.common{// <summary> /// Map correction data help class // </summary> Public classMapoffsetdatahelper {#regionConstructors and variablesPrivate stringOffsetfullpath =string. Empty;// <summary> /// constructor // </summary> /// <param name= "path" > Corrective data File path </param> PublicMapoffsetdatahelper (stringPath) {Offsetfullpath = path; }#endregion #regionPrivate methodsPrivate voidGetoffsetdata (action<mapcoord> mapcoordhanlder) {using(FileStream stream =NewFileStream (Offsetfullpath, FileMode.OpenOrCreate, FileAccess.Read)) {using(BinaryReader reader =NewBinaryReader (stream)) {int_size = (int) stream. LENGTH/8; for(inti = 0; i < _size; i++) {byte[] _source = reader. Readbytes (8); Mapcoord _coord = Tocoord (_source); Mapcoordhanlder (_coord); } } } }// <summary> /// convert bytes to a specific data object // </summary> /// <param name= "bytes" >bytes</param> // <returns>MapCoord</returns> PrivateMapcoord Tocoord (byte[] bytes) {//longitude, latitude, x offset, y offset "two bytes"Mapcoord _coord =NewMapcoord ();byte[] _b1 =New byte[2], _b2 =New byte[2], _b3 =New byte[2], _b4 =New byte[2]; Array.copy (bytes, 0, _b1, 0, 2); Array.copy (Bytes, 2, _b2, 0, 2); Array.copy (Bytes, 4, _b3, 0, 2); Array.copy (Bytes, 6, _B4, 0, 2); _coord. Lon = bitconverter.toint16 (_b1, 0); _coord. Lat = bitconverter.toint16 (_b2, 0); _coord. X_off = bitconverter.toint16 (_b3, 0); _coord. Y_off = bitconverter.toint16 (_b4, 0);return_coord; }#endregion #regionGet a set of corrective data// <summary> /// Get Corrective data collection // </summary> /// <returns> Corrective data collection </returns> PublicList<mapcoord> getmapcoordlist () {list<mapcoord> _mapcoordlist =NewList<mapcoord> (); Getoffsetdata (c = _mapcoordlist.add (c));return_mapcoordlist; }// <summary> /// Get Corrective data collection // </summary> /// <returns> Corrective data collection </returns> PublicArrayList getmapcoordarraylist () {ArrayList _mapcoordarraylist =NewArrayList (); Getoffsetdata (c = _mapcoordarraylist.add (c));return_mapcoordarraylist; }#endregion}}
-----------------------------------------------------------------------------------------------
usingSystem.Collections;usingYanZhiwei.DotNet2.Utilities.Models;usingYanZhiwei.DotNet2.Utilities.Tool;namespaceyanzhiwei.dotnet2.utilities.common{// <summary> /// map correction Help class // </summary> Public classMapoffsethelper {/** Reference:*1.http://www.apkbus.com/forum.php?mod=viewthread&tid=137621&extra=page%3d1&page=1*2.http://yanue.net/post-122.html*3.http://go2log.com/2011/08/30/%e4%b8%ad%e5%9b%bd%e5%9c%b0%e5%9b%be%e5%81%8f%e7%a7%bb%e6%a0%a1%e6%ad% a3php%e7%ae%97%e6%b3%95/*4.http://www.devdiv.com/ios_gps_google_-blog-60266-10835.html */ #regionConstructors and variablesPrivateArrayList mapcoordarraylist;// <summary> /// constructor // </summary> /// <param name= "Offsetdata" > Corrective Data </param> PublicMapoffsethelper (ArrayList offsetdata) {mapcoordarraylist = Offsetdata; }#endregion #regionPrivate methodsPrivateMapcoord Queryoffsetdata (Latlngpoint point) {Mapcoord _search =NewMapcoord (); _search. Lat = (int) (Point. Laty * 100); _search. Lon = (int) (Point. Lonx * 100); Mapoffsetcomparer rc =NewMapoffsetcomparer ();int_findedindex = Mapcoordarraylist.binarysearch (0, Mapcoordarraylist.count, _search, RC); Mapcoord _findedcoord = (Mapcoord) Mapcoordarraylist[_findedindex];return_findedcoord; }#endregion #regionEarth coordinates (WGS-84) to Mars coordinates (GCJ-02)// <summary> /// Earth coordinates (WGS-84) turn Mars coordinates (GCJ-02) // </summary> //<param name= "Wgspoint" > Earth coordinates (WGS-84) </param> ///<returns> Mars coordinates (GCJ-02) </returns> PublicLatlngpoint wgs84togcj02 (Latlngpoint wgspoint) {Mapcoord _findedcoord = Queryoffsetdata (wgsPoint);Double_pixy = Maphelper.lattopixel (Wgspoint.laty, 18);Double_pixx = Maphelper.lontopixel (Wgspoint.lonx, 18); _pixy + = _findedcoord.y_off; _pixx + = _findedcoord.x_off;Double_lat = Maphelper.pixeltolat (_pixy, 18);Double_LNG = Maphelper.pixeltolon (_pixx, 18);return NewLatlngpoint (_lat, _LNG); }#endregion #regionMars coordinate turn (GCJ-02) Earth coordinates (WGS-84)// <summary> / /Mars coordinate turn (GCJ-02) Earth coordinates (WGS-84) // </summary> ///<param Name= "Gcjpoint" > Mars coordinates turn (GCJ-02) </param> ///<returns> Earth coordinates (WGS-84) </returns> PublicLatlngpoint gcj02towgs84 (Latlngpoint gcjpoint) {Mapcoord _findedcoord = Queryoffsetdata (gcjPoint);Double_pixy = Maphelper.lattopixel (Gcjpoint.laty, 18);Double_pixx = Maphelper.lontopixel (Gcjpoint.lonx, 18); _pixy-= _findedcoord.y_off; _pixx-= _findedcoord.x_off;Double_lat = Maphelper.pixeltolat (_pixy, 18);Double_LNG = Maphelper.pixeltolon (_pixx, 18);return NewLatlngpoint (_lat, _LNG); }#endregion}}
[C #] using corrective data to process Earth coordinates (WGS-84) and Mars coordinates (GCJ-02) transformations