如何在PointLatLng中输入字符串?是否还有其他输入字符串的方法?

huangapple go评论71阅读模式
英文:

How do I input string in PointLatLng? Is there another way for me to input string?

问题

I want to input my lat and long but it has space in it so it won't accept the input.

The lat and long in my database is formatted in DMM (it's like this 41 24.2028, 2 10.4418)

I have tried removing the whitespaces but it leads me to different location

private void button1_Click(object sender, EventArgs e)
{
gMapControl1.DragButton = MouseButtons.Left;
gMapControl1.MapProvider = GMapProviders.GoogleMap;

lat = Convert.ToDouble(textBox1.Text);
longi = Convert.ToDouble(textBox2.Text);
gMapControl1.Position = new PointLatLng(lat, longi);

gMapControl1.MinZoom = 5;
gMapControl1.MaxZoom = 100;

gMapControl1.Zoom = 15;

PointLatLng point = new PointLatLng(lat, longi);
GMapMarker marker = new GMarkerGoogle(point, GMarkerGoogleType.red_small);

GMapOverlay markers = new GMapOverlay("markers");

markers.Markers.Add(marker);

gMapControl1.Overlays.Add(markers);

}

英文:

I want to input my lat and long but it has space in it so it won't accept the input.

The lat and long in my database is formatted in DMM (it's like this 41 24.2028, 2 10.4418)

I have tried removing the whitespaces but it leads me to different location

    private void button1_Click(object sender, EventArgs e)
    {
        gMapControl1.DragButton = MouseButtons.Left;
        gMapControl1.MapProvider = GMapProviders.GoogleMap;

        lat = Convert.ToDouble(textBox1.Text);
        longi = Convert.ToDouble(textBox2.Text);
        gMapControl1.Position = new PointLatLng(lat, longi);

        gMapControl1.MinZoom = 5;
        gMapControl1.MaxZoom = 100;

        gMapControl1.Zoom = 15;

        PointLatLng point = new PointLatLng(lat, longi);
        GMapMarker marker = new GMarkerGoogle(point, GMarkerGoogleType.red_small);

        GMapOverlay markers = new GMapOverlay("markers");

        markers.Markers.Add(marker);

        gMapControl1.Overlays.Add(markers);
    }

答案1

得分: 0

41 24.2028 意味着41度和24.2028分钟。这本身不是有效的语法,然而,您可以轻松地拆分度和分钟部分:

var splitX = "41 24.2028".Split();
var degreeX = double.Parse(splitX[0]);
var minutesX = double.Parse(splitX[1]);

最后,您需要将分钟转换为十进制度:

var resultX = degreeX + minutesX / 60;

因此,最终您会得到41.40338。

英文:

41 24.2028, 2 10.4418 from my understanding means 41 degree and 24.2028 minutes. This per se isn't a valid syntax, however you can easily split the degree- and the minutes-part:

var splitX = "41 24.2028".Split();
var degreeX = double.Parse(splitX[0]);
var minutesX = double.Parse(splitX[1]);

Finally you need to convert the minutes to decimal-degrees:

var resultX = degreeX + minutesX / 60;

So finally you get 41.40338.

huangapple
  • 本文由 发表于 2023年2月8日 20:10:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/75385603.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定