显示经度和纬度存储在SQL数据库中的地图图标 [英] Displaying map icons where the longitude and latitude is stored in a SQL database
本文介绍了显示经度和纬度存储在SQL数据库中的地图图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要显示许多不同位置的地图图标,其中纬度和经度存储在sql数据库中。我怎么处理这个?
我尝试过:
试过硬编码,但是我需要从数据库中进行。
I need to display map icons for a number of different locations, where the latitude and longitude is stored in a sql database. How can I approach this?
What I have tried:
Tried hardcoding and that works, but I need to do it from a database.
推荐答案
我会给你一个模糊的答案,因为我所知道的是使用C#, SQL的一些风格,以及未知的显示媒体。
对于SQL部分,我将使用最小的表结构
I will give you a vague answer, as all I know is are using C#, some flavor of SQL, and an unknown display medium.
For the SQL portion, I will use a minimal table structure
CREATE TABLE dbo.Locations (
LocID INT IDENTITY(1,1) NOT NULL,
locName NVARCHAR(100) NULL, -- Location Name
LocLat DECIMAL(9,6) NULL, -- Latitude
LocLng DECIMAL(9,6) NULL, -- Longitude
CONSTRAINT [PK_Locations_ID] PRIMARY KEY CLUSTERED([LocID] ASC) ON [PRIMARY]
) ON [PRIMARY]
GO
INSERT Locations( LocName, LocLat, LocLng)
VALUES ('Los Angeles', 34.05223, -118.24368)
, ('Santa Monica', 34.02421, -118.49647)
, ('Redondo Beach', 33.84918, -118.38840)
, ('Newport Beach', 33.62834, -117.92793)
, ('Long Beach', 33.77005, -118.19373)
GO
下一个2部分将在C#中;首先是POCO
The next 2 parts will be in C#; first a POCO
CREATE TABLE dbo.Locations (
public int LocID
public string LocName
public double LocLat
public double LocLng
}
第二个是人口
And the second will be population
// write your own code, but here are the highlights
string cmd = "SELECT LocName, LocLat, LocLng FROM Locations"
// create DataReader and use above to populate
// return Collection<Locations> from above DataReader
最后一件事就是显示这个。不知道你打算如何做到这一切我都可以tell就是传递上面的集合并遍历它。
Last thing is to display this. Without knowing how you intend to do this all I can tell is to just pass the above collection and iterate through it.
这篇关于显示经度和纬度存储在SQL数据库中的地图图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文