How do I plot a vector (with a magnetic heading and magnitude) in Google Maps? - google-maps

I have a table with a year's worth of wind data for a specific latitude longitude. I want to plot this as an arrow in Google Maps. Each data point has a timestamp, heading (true), and magnitude (knots), but it is just contained in a spreadsheet.
I was thinking the easiest way is to just create a new layer using geoJSON data, but I've never used geoJSON before.
How can I plot this in Google Map api v3? Thanks!
EDIT:
I did some research, and I think the best way is to just place a marker over the lat long point, and generate a ton of arrow images (probably in 5 degree and .5 knot increments, so I don't have a million images). Then just title each arrow based on its parameters (something like 01030.png, where 010 is the direction and 30 stands for 3.0 knots) and when the script calls for the marker image, just include those attributes when it calls for the image name.
I'll post the code when I make it, so other people can see.

Related

generate layers for maps (Google or OpenLayers)

I'm trying to develop a software that gets data from a text file and generates a map layer. The map later on is going to be cut into tiles and used as overlay for Google Maps API or OpenLayers.
The data stored in the text file is weather data. The file has data about 1 x 1 squares. For example: there is .9 chance of rain for lat 1-2 and lon 5-6. I have to use the data provided in the data file and can't use pre-generated layers.
I generate the map by dividing a background white PNG into 360 horizontal boxes and 180 vertical ones and color each one based on the data available in the text file.
My problem is the fact that there are 180 latitudes and 360 longitudes but the base map for OpenLayers and Google Maps is a square. In other words, number of latitudes equals the number of longitudes in OpenLayers and Google Maps. Moreover when I take a world map and stretch it vertically the lines do not align at all.
Example:
OpenLayer base map (256px x 256px):
Generated layers (256px x 256px):
When I add the layer on top of the base map. Continents don't match. I don't have this problem when i use a non-square(256px x 128px) base map.
My question is how should I generate my layover so it works with a square world map that is being used by Google and OpenLayers?

Get total degrees latitude/longitude displayed on a Google map when world wraps- Javascript v3 API

I am writing some code which clusters markers on a Google map. The clustering algorithm relies on knowing how many degrees latitude and longitude are currently visible to the user, as I break the map into a grid of n/map_pixels_width x n/map_pixels_height squares and need to know how many degrees of lat/lon are in each square to know which square each marker point belongs to.
Under normal circumstances where the map does not wrap this is relatively easy to calculate using getBounds() on the Google Map object and doing the calculations to figure out the latitudinal and longitudinal distances between the returned North-East and Sout-West points. Where I'm running into issues is where the map is zoomed out to the extent that it wraps the entire Earth > 1 times. For example, I can zoom out the map so that the entire Earth is "tiled" 5 times over which equates to 360 * 5 = 1800 longitudinal degrees and, but then the call to getBounds() no longer provides useful information:
m.getBounds().getNorthEast().lat()
88.31833020528785
m.getBounds().getNorthEast().lng()
180
m.getBounds().getSouthWest().lat()
-88.5485785544835
m.getBounds().getSouthWest().lng()
-180
Basically, the longitudes getBounds() reports are just the min and max for one whole globe which says nothing about how many times the Earth is repeated. Although Google Maps doesn't tile the map vertically (it just inserts gray filing space if zoomed out far enough), I have conceptually the same problem -- I need to know how many total degrees of space the vertical area would consume.
Is there a way to get the total number of visible longitudinal degrees?
So based on this answer to another question, I found a (hackish) way to solve this. Basically, the Google Maps OverlayView class has a getProjection() method returning a MapCanvasProjection object, which in turn has a getWorldWidth() method which returns the width of the world at the current zoom level in pixels. So the way to solve the problem then is to:
Add a dummy OverlayView to the map that doesn't actually present an overlay.
Get the overlay's projection.
Get the world width from the projection.
Calculate the number of visible longitudinal degrees as pixel_width_of_map_element / world_width_in_pixels * 360
It would be better if there were a way to do this without creating a dummy overlay, but this method seems to work.

Adding the marker to Google Maps external link

I have website that uses Google maps to plot the location of registered businesses. This uses javascript and shows the orange marker to pinpoint the exact location. I'm trying to build a link to the actual google maps page and my code is doing what I want it to except the marker doesn't show up. Is there another peice of code I can add to this to make it show up?
Full Sized Map
To add a pin you need the q parameter. It holds q=latitude+longitude+(url-encoded-text)
Here is an example of hybrid map with weather - pin at Embassy Suites, map centered on Horseshoe Falls
https://maps.google.com/maps?hl=en&ll=43.076,-79.074&spn=0.0212,0.0496&t=h&z=16&q=43.0795N+79.0818W+(Nice%20Hotel)&lci=weather
hl= two letter language code
ll= the map center using coma
separated +/- values
spn= the viewport span in degrees, works with
the z parameter
t= map type {m|k|h|p}
z= is the zoom factor
q= latitude+longitude+(url-encoded-text), the lat/lon in q have to be
followed by a letter - N/S or E/W instead of using +/-
lci= special codes, coma separated - i know of weather, transit_comp, com.panoramio.all
layer= additional layers, e.g. t for traffic
Google is changing things with the new Google Maps and a lot of functionality has been removed/replaced. You can check the new Maps Engine here http://mapsengine.google.com/map/

Google Maps V3 creating polygon from county name in XML data

Well I have run into a bit of a small problem and I am not sure how to approach this. I have this test map.
http://www.mesquiteweather.net/googlemap_poly.html
Which creates polygons based on data from this XML file.
http://www.mesquiteweather.net/xml/warnings.xml
It displays weather alerts/watches/warnings etc on the map from the data which makes the polygon that shows what area the alert is in and I have an array in another file that assigns the color. All that works great.
Here is my problem. The XML feed doesn't always display alerts with polygon cords that can be split to create latlng object to create the polygons, I will only get county names half the time so there may be alerts in the feed but they will never get displayed if there is no polygon cords. If you look at the feed for cap:polygon you'll see not all of them have it. Right above it though is areaDesc which is the county name. So is there an easy way to create a polygon base on the county name from that data and how?
I have been searching the web with no results. I did read about fusion tables but will that work and can I use that to draw the polygons based on the data from the feed then have fusion tables draw it out? I don't know, I am doing stuff with Google Maps I have never done before so I am out of my element and could use some guidance and assistance. Any suggestions or advice would be greatly welcomed so I can put this project to sleep.
-Thanks
You can use FusionTables to display a FusionTablesLayer with specific counties on it, and style those polygons dynamically (with up to 5 style rules).
FusionTable containing US counties
Selected counties
Example that displays the counties (using a FusionTablesLayer) on the map
Proof of concept, not sure this will be usable with this many counties.
Probably OK with a small number of counties (your original example)

algorith or formula to get a set of lat lon values based on viewport and zoomlevel

I need to display around 50,000 markers on the map. But i was able to plot only 10000 points. I thought of implementing this way correct me if i'm wrong...
Instead of fetching whole data at once just fetch points that are in the viewport and depending on the zoomlevel.
ex:google maps: at one zoomlevel only states are shows if we zoom in further cities are shown
I'm stuck with the zoomlevel.. how to relate zoomlevel and viewport.Is there any algorithm or formulae that helps in getting the lat long values or it needs to be hardcoded in the database like for particular lat-lon this is the zoomlevel range so while fetching range is checked.
i'm using openlayers bbox feature to get the bounds
Thanx in advance
google.maps.Map.getBounds() will return the lat/long bounds of the viewport.
50,000 markers is a lot compared to what Google Maps can handle; you would have to be way zoomed in to have few enough markers to be under the limits. You might do better by creating custom tiles with dots instead of markers. You can see an example at
http://maps.webfoot.com/demos/election2008/
Scroll down to the third overlay to see dots; select zip codes to see LOTS of dots.