mapbaidu 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/map_baidu.rb +77 -18
  2. metadata +1 -1
data/lib/map_baidu.rb CHANGED
@@ -48,24 +48,50 @@ class MapBaiDu
48
48
 
49
49
  def round (distance)
50
50
 
51
- current_lat = self.get_lat.round(4)*10000
52
- current_lng = self.get_lng.round(4)*10000
53
-
54
- result_array = Array.new()
55
- begin_lng = (current_lng - (distance/100).to_int).to_i
56
- begin_lat = (current_lat - (distance/100).to_int).to_i
57
- i = 0
58
- loop_times = 2 * (distance/100).to_int + 1
59
-
60
- while i < loop_times
61
- j=0
62
- while j < loop_times
63
- result_array.push([(begin_lng + i)/10000.to_f, (begin_lat + j)/10000.to_f])
64
- j +=1
51
+ current_lat = self.get_lat.round(4)*10000.to_int
52
+ current_lng = self.get_lng.round(4)*10000.to_int
53
+
54
+ #result_array = Array.new()
55
+ #begin_lng = (current_lng - (distance/100).to_int).to_i
56
+ #begin_lat = (current_lat - (distance/100).to_int).to_i
57
+ #i = 0
58
+ #loop_times = 2 * (distance/100).to_int + 1
59
+ #
60
+ #while i < loop_times
61
+ # j=0
62
+ # while j < loop_times
63
+ # result_array.push([(begin_lng + i)/10000.to_f, (begin_lat + j)/10000.to_f])
64
+ # j +=1
65
+ # end
66
+ # i +=1
67
+ #end
68
+
69
+
70
+ result_array = Array.new
71
+
72
+ radius = (distance.to_f/100).ceil
73
+
74
+
75
+ y = radius-1
76
+ while y >=0
77
+ x = Math.sqrt(radius**2 - y**2).ceil.to_i
78
+ while x >= 0
79
+ result_array.push([(current_lng- x), (current_lat - (y+1))])
80
+ result_array.push([(current_lng+ x), (current_lat - (y+1))])
81
+
82
+ result_array.push([(current_lng- x), (current_lat + (y+1))])
83
+ result_array.push([(current_lng+ x), (current_lat + (y+1))])
84
+
85
+ result_array.push([(current_lng- x), (current_lat - (y))])
86
+ result_array.push([(current_lng+ x), (current_lat + (y))])
87
+ x -= 1
65
88
  end
66
- i +=1
89
+ y -=1
67
90
  end
68
91
 
92
+
93
+ puts result_array.length == (2*radius + 1) **2
94
+
69
95
  return result_array
70
96
  end
71
97
 
@@ -90,11 +116,44 @@ class MapBaiDu
90
116
  else
91
117
  return (number*10000).to_i.to_s
92
118
  end
93
-
94
-
95
119
  end
96
120
 
97
-
121
+ #
122
+ #def round2(distance)
123
+ #
124
+ # current_lat = self.get_lat.round(4)*10000
125
+ # current_lng = self.get_lng.round(4)*10000
126
+ #
127
+ # s_r = Array.new
128
+ #
129
+ # radius = (distance.to_f/100).ceil
130
+ # puts 'radius:' << radius.to_s
131
+ #
132
+ # y = radius-1
133
+ #
134
+ # puts current_lng.to_s << ":" << current_lat.to_s
135
+ # current_lng = current_lng.to_i
136
+ # current_lat = current_lat.to_i
137
+ #
138
+ # while y >=0
139
+ # x = Math.sqrt(radius**2 - y**2).ceil.to_i
140
+ # while x >= 0
141
+ # s_r.push([(current_lng- x), (current_lat - (y+1))])
142
+ # s_r.push([(current_lng+ x), (current_lat - (y+1))])
143
+ #
144
+ # s_r.push([(current_lng- x), (current_lat + (y+1))])
145
+ # s_r.push([(current_lng+ x), (current_lat + (y+1))])
146
+ #
147
+ # s_r.push([(current_lng- x), (current_lat - (y))])
148
+ # s_r.push([(current_lng+ x), (current_lat + (y))])
149
+ # x -= 1
150
+ # end
151
+ # y -=1
152
+ # end
153
+ #end
154
+ #
155
+ #
156
+ #
98
157
 
99
158
 
100
159
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mapbaidu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: