¡Ayúdanos a traducir esta Web y consigue licencias gratis!
Usuario anónimo  |  Ingresar  |  Regístrate
Mensaje dentro General Discussions

How to zoom map centered on a particular zip code

Responder 
#1 - 14/12/2011 19:12:56 Reporta abuso | Link permanente
riflegear
Fecha de registro: 16/07/2010
4 posts en todos los foros
How to zoom map centered on a particular zip code

Responder Citar
I am fairly new to using this library so I could use some general guidance on this task.  I have a map of the United States and a database with dealers and their addresses and coordinates.  Customers can click in a drop-down and select a state and then I center the map on the state and create all the markers for that state.  I would like to enhance this so that the user could also just key in their zip code and then I would like to center the map on that zip code and then find all the dealers within a radius (say 10, 25, 50, or 100 miles) and then load up all the markers within that radius and zoom the map to show that radius.  Is this possible?  What do you all think would be the way to go about doing this?

Thanks,
David
Volver arriba

Respuestas
De en 15
#2 - 17/12/2011 1:48:39 Reporta abuso | Link permanente
riflegear
Fecha de registro: 16/07/2010
4 posts en todos los foros
RE: How to zoom map centered on a particular zip code

Responder Citar
Map is here: http://www.riflegear.com/t-FFLMap.aspx

Well I was able to mostly figure this out and thought I would share since I didn't get any responses here about this.  The query below utilizes a formula that can be used to calculate a distance from a specific lat and lng - in this example using coordinates 37,-122.  This query is for MySQL but I am using SQL Server and managed to get it to work using a table based function.  

SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < 25 ORDER BY distance LIMIT 0 , 20;

The only part I couldn't figure out is how to zoom the map to the bounds of the found coordinates.  I just ended up hard-coding some zoom factors based upon the distance the user selects (5, 10, 25, etc.. miles)

EDITADO 12/17/2011 9:25:29 PM: added link to map
Volver arriba
De en 15

Powered by Subgurim.NET