I have a Google Map where I'd like to display some markers etc.
If you open the website, it sets session to "geometrycollection empty". When the map is fully loaded, it makes an AJAX request with NE & SW lat and lng as parameters.
Handle method for AJAX looks like that:
$contain = $this->locationsManager->getContainOfAreas($this->getSession("union")->area, $polygon);
$area = $this->locationsManager->getDifferentiatedArea($polygon, $this->getSession("union")->area);
$coordinates = $this->locationsManager->getLocationsCoordinates($area["polygon"]);
$this->getSession("union")->area = $this->locationsManager->getUnionOfAreas($this->getSession("union")->area, $area["polygon"])["unionArea"];
But when I try to find out if area B ($this->getSession("union")->area - union of areas (viewports) user "visited") contains area A ($polygon - current viewport in Google Maps), it returns wrong results (I drew polygons from the variables via Google Maps Polygons and they were different).
This is SQL command for getting result of getContainOfAreas:
SELECT ST_CONTAINS(ST_GEOMFROMTEXT(?), ST_GEOMFROMTEXT(?)) AS result;
Do you know what I'm doing wrong?
Related
I currently have the task of integrating some GPS data stored in a MySQL
database with google earth. The objective is to create
placemarks/waypoints of these readings and display them on google
earth.
I googled the task and came across an article :
"A Database Driven Earth App: Using PHP & MySQL with the Earth API" .
Located at the URL:
https://developers.google.com/earth/articles/phpsqlearth
I followed it successfully; until I came to where I had to create the
placemarks. The main issue is that the 'createPlacemark' function
has the following signature:
"createPlacemark(name,address,type,lat,lng)" .
My main point of concern is the lat and lng arguments (latitude and longitude), because the GPS data in the
database are all in the format :
"N5 bb.xxx E8 cc.yyy".
No separate longitude or latitude data was stored. The data is being
collected via a garmin gps.
I was thinking that perhaps I could resolve this issue by
doing this:
var point = ge.createPoint('N5 bb.xxx E8 cc.yyy ') ,
and forget about the
point.setLatitude(parseFloat(lat))
and
point.setLongitude(parseFloat(lng)) statements.
However , I wanted to confirm if I was on the right path seeing I will be away from my development machine for a few days.
No, calling the GEPlugin method createPoint like you have it
var point = ge.createPoint('N5 bb.xxx E8 cc.yyy');
would create a point with the ID N5 bb.xxx E8 cc.yyy - the createPoint method only takes a single string parameter and that is used to set the ID of the object.
As you have it the resultant point KML would look like this:
<Point id="N5 bb.xxx E8 cc.yyy">
</Point>
You would need to call one or more methods on the actual point object that is created to set the latitude and longitude data. Either point.set() or point.setLatitude() and point.setLongitude() - you would then finally set the point to the placemarks geometry for it to work.
looking at it all you really need to do is to parse the Garmin GPS using a simple function. Simply splitting the string using white-space should work fine.
//parse a string in the Garmin format "N5 bb.xxx E8 cc.yyy"
//returns a kmlpoint
function gpsToPoint(data) {
var parts = data.split(' ');
var point = ge.createPoint('');
point.setLatitude(parseFloat(parts[1]));
point.setLongitude(parseFloat(parts[3]));
return point;
}
Then just change the createPlacemark function so that you create the point object with the new gpsToPoint() method passing in the the Garmin data.
This would give you KML like
<Point>
<coordinates>bb.xxx,cc.yyy,0</coordinates>
</Point>
I'm using Google Maps to calculate distances between a user-entered address and our store locations. Once this data is read in, I'd like to use jQuery .tablesorter() to sort the table from closest to furthest store. However, the data read in from Google Maps is not being recognized by the jQuery .tablesorter() function. I tried implementing the setTimeout() suggestion on this thread (JQuery tablesorter appended data not sorting) and numerous other fixes that did not work. I understand what's happening (the DOM not recognizing data written to the page after it's been constructed), but I'm not entirely sure how to fix it. Any ideas? Thanks!
Here's the URL to the test page if you'd like to see what's happening: http://www.gregcklotz.com/Larry/Locations.php
You just need to update the table after adding all of the distance data into the columns:
for (i = 0; i < stores.length; i++)
{
address = new google.maps.LatLng(lat, lng);
coords = new google.maps.LatLng(stores[i].lat, stores[i].long);
distance = (.621371192237334 * google.maps.geometry.spherical.computeDistanceBetween(address, coords)/1000).toFixed(1);
$("tr.store"+stores[i].store+" td:last").text(parseInt(distance));
}
// update the table data
$("table").trigger("update");
map.setCenter(marker.getPosition());
My application create map using Google Maps v3 that have lots of markers and clusters on it, and it works fine.
Same map I have to show also in another browser window, but for some reason it can't (getting only empty map, without markers/clusters on it). I checked error in Firebug, and there is an message:
NetworkError: 414 Request-URI Too Large
So - same maps, in first browser window is ok, in second it is not.
Just to say that I'm opening second map (in second window) by sending parameters about every marker I have on first map, so URL is very long (2700 characters).
Is there some way to solve this? Is it a problem with long url string?
Can you help me with this?
The problem is in the URL you generated. Google specifies a limit of 2000 chars for the passed URL and we should stick with it.
I solved the problem in my application by generating a hash of the URL before passing it over to Google.
1) Create a database table to store your hashes. Columns can be hash, params, timestamp. You can improve your code by deleting hashes older than certain time, keeping the table small and fast.
2) Create a code (my_google_map_helper/get_hash) to generate the hash to be passed to Google and stick it somewhere. I am using PHP, so my code is:
// generate my hash
$hash = sha1(serialize($_GET));
// run an insert ignore into my hashes' table
// get the hash where the hash is $hash
// print my hash
3) Create a code (get_kml) to retrieve the params saved into the database from a given hash
if(isset($_GET['hash'])):
// select params from my hash table where hash = $_GET['hash']
// unserialize the saved params
// generate and return my KML file
endif;
4) Change your JavaScript so it generates the hash before calling the Google function:
$.get('my_google_map_helper/get_hash?' + MY_LONG_PARAMS_LIST, true)
, function(hash){
Polygons = new google.maps.KmlLayer(
{url:'http://my_url/get_kml?hash=' + hash , map:MAP}
);
}
);
Have fun!
i've already read this question, but i have some regrets to apply in my situation becose i have many markers (atm ~5000, grown everyday).
In my application the user place his marker (lets call it marker A) clicking the map or via a geocode by address; I have to know if there is a marker in a specific radius of marker A.
As i said, i cant iterate throught all the markers, it will probably kill the user browser, and if possible i'll love to avoid ajax requests to search into my database.
Actually i insert the markers on the map via MarkerManager
Is there a way to search only between the markers in the map's visible area?
After many many research, i ended with the iteration solution (demo here).
To decrease the number of items to iterate with, i divide in base of the state (at the moment is enaught), maybe in the future i can add further divisions.
If it can be usefull to someone else, my 'solution' implies an array like:
places = {
"it":[
"Rome",
"Venice"
],
"fr":[
"Paris",
"Lyon"
],
"es":[
"Madrid",
"Barcelona",
"Girona"
]
}
And a google geocode with the user marker coords to get the state ('fr', 'it') where to look for places.
you can use the method getBounds() which will retrieve LatLngBounds object. With this object, you can call the methods getNorthEast(); getSouthWest() methods which will retrieve the Northwest and Southeast bounds of your map respectively.
Knowing these bounds, you can perform calculations in your application
(pseudo code):
if (yourPointLatitude > southWestBoundLatitude && yourPointLatitude < northWestBoundLatitude && yourPointLongitude > northWestBoundLongitude && yourPointLongitude < southEastBoundLongitude)
{
//take some action, the point is in the map bounds
}
Note: this case is only for specific geographic location -> it will only work for the northeast quarter of the world (for example Europe). If you want for different location, use other logic in the if statement and that's it...
Edit: look at these links for details:Map
LatLngBounds
I'm currently working on developing a Google Maps API implementation that overlays topographic data from USGS Terra Server. I think I have it pretty much under hand except that I can't figure out how to determine the name of the quad, name, & scale for the current tile being served from Terra Server. If you check out this site and zoom into the map that information is being displayed so it must be possible:
http://www.trails.com/topomap.aspx?trailid=fgu003-087
Here are links to some articles which explains more how the images are named by Terra Server:
About MSR Maps
STANDARDIZED DATA SET NAMES FOR DRG PRODUCTS
I'm hoping that some geoloc expert out there has already done this and can point me in the right direction. I'd appreciate if you could give me any clues how I might determine this information from the current map view when overlaying the USGS topo data over Google Maps to produce a user experience much like that of the example map about.
Thanks in advance for your help!
You can use the OGC Style Web Map Server Microsoft also hosts. These have a relatively simple lat/lon/scale structure for fetching data, rather than leaving you guessing about the numbers. Here is a url for Aerial. The Scale variable s ranges from 11-21. The t variable lets you choose between Aerial and Topos. Set t=2 for Topos - here is Topo URL.
To get the quad name and map reference etc. You will have to index the topos and build a database. If you have the Topos on a CD and they are in Tiff format you can use GDALTindex to build this index. Beyond this your queries reduce to Point-in-Polygon type, which you can perform using Net Topology Suite.
Since there is no simple intuitive mapping for all the different map-sets and scales, a precomputed index will be the best way to go.
Gdaltindex can index tif files and produce an index in Shapefile format. This can be mapped into MySQL Geometries using Ogr MySQL support.
In the example, the trails.com server is delivering the custom tile images through their own CDN and displaying those tiles over top of Google Maps using a .NET WebHandler.
Since you need the data to come from MSRMaps.com and not [Trails.com][3], you will point the MSRMaps.com WebHandler instead.
Below is how trails is doing it. Replace the getTileUrl function with something that makes a call to the msrmaps.com server instead, such as MSR Tile Link
var layer = new GTileLayer(new GCopyrightCollection(''), 1, 21);
layer.getTileUrl = function(a, b)
{
var ll = G_NORMAL_MAP.getProjection().fromPixelToLatLng(new GPoint(a.x * 256, (a.y + 1) * 256), b);
var ur = G_NORMAL_MAP.getProjection().fromPixelToLatLng(new GPoint((a.x + 1) * 256, a.y * 256), b);
return "http://cdn-www.trails.com/services/TopoGetGoogleMapTile.ashx?z=" + b + "&style=drgsr&ll=" + ll.y + "," + ll.x + "&ur=" + ur.y + "," + ur.x;
}
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
map.setUIToDefault();
var mapType = new GMapType([layer], G_NORMAL_MAP.getProjection(), 'Trails', { errorMessage: google.mapError, textColor: "white", linkColor: "white" });
map.addMapType(mapType);
map.setMapType(mapType);