英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论