mysql经度和纬度设计,MySQL纬度和经度表设置

I want to store latitude and longitude values of places in a mysql database table. With the future in mind I will want to be able to find these places within a certain radius of a specific location. Having said that, what datatypes should I store the latitude and longitude values in? Please could you provide me with a create table script for columns like so:

place_id | lat | long

Is there perhaps a column I am missing in the above table that will provide me with additional information that I may not see I need at the current time?

Thanks for any help.

解决方案

You should store the points in a singe column of datatype Point which you can index with a SPATIAL index (if your table type is MyISAM):

CREATE SPATIAL INDEX sx_place_location ON place (location)

SELECT *

FROM mytable

WHERE MBRContains

(

LineString

(

Point($x - $radius, $y - $radius),

Point($x + $radius, $y + $radius)

)

location

)

AND Distance(Point($x, $y), location) <= $radius

This will drastically improve the speed of queries like "find all within a given radius".

Note that it is better to use plain TM metrical coordinates (easting and northing) instead of polar (latitude and longitude). For small radii, they are accurate enough, and the calculations are simplified greatly. If all your points are in one hemishpere and are far from the poles, you can use a single central meridian.

You still can use polar coordinates of course, but the formulae for calculating the MBR and the distance will be more complex.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值