i need some help with google map api v3 markers.
I got an array which contains coordinates i retrieve from a file. I am trying to traverse the array, and plot them using the markers.
Traversing the array to retrieve the coordinates is not a problem, however, when i start using the coordinates to plot on google map. i realise that i am getting (NaN, NaN) as the coordinates.. Because of this, i am not able to do the plotting.. any idea why isit? Thanksss
my codes so far:
var temp = new google.maps.LatLng(myObject[o]);
retrieverouteMarker(temp);
The constructor for LatLng takes two arguments (the latitude and longitude of the point), so this line is clearly wrong:
var temp = new google.maps.LatLng(myObject[o]);
Of course, since we have to idea what myObject is, or what the function retrieverouteMarker does, there isn't much more we can do to help.
Related
I'm using Leaflet JS to build my maps, but I'm having a few issues selecting layers.
I'm aiming to fit my map to a polygon. Leaflet generates a Leaflet ID for each element on the map, but these IDs are random. So I want to create an array which links each Leaflet ID with a known polygon ID.
The concept comes from here How to interact with leaflet marker layer from outside the map? but I'm unsure how to implement it.
The object 'map._layers' stores all the elements including the ID of each polygon. So I'm looping through it as follows:
var idstore = [];
for (var x in map._layers) {
// here idstore[x['polyid']] = x;
}
Now I can use that array to associate my polygon IDs to Leaflet IDs. The resulting array should be as follows:
array('polygonid'=>'leafletid','155447'=>'478','748745' => 479);
My problem is the loop isn't working correctly. I can only see the first 2 records coming up which are actually overlays (map tiles). The elements are definitely in that object though.
What am I doing wrong?
A good first step would be looking through the Leaflet reference documentation and using the documented .eachLayer function instead of a for loop on a private variable.
var idstore = [];
map.eachLayer(function(layer){
// ...
});
I have used the point based clustering http://bingmapsv7modules.codeplex.com/wikipage?title=Point%20Based%20Clustering
This is great for clustering. However, I am trying to find the longitude latitude of a cluster which contains first pushpin every 5 second using setInterval...obviously I am just simplifying the scenario..
var pushpin = pinLayer[0]; grabbing first story of the pin
var currentClusterIndex = pushpin._clusterIndex; // get the cluster index
var currentCluster = pinLayer.GetPinByClusterIndex(currentClusterIndex);// get cluster info
var currentLatitude = currentClusterLocation.latitude; // get latitude
var currentLongitude = currentClusterLocation.longitude; // get longitude
Now the latitude and longitude is correct when the map loads, but right after user interaction it's rarely correct, it's giving latitude longitude of different cluster.
Could someone possibly help with this?
It's not 100% clear what you want to do. Your code seems to indicate you want to take a pushpin that's on the map and get it's cluster index and use that to get a reference the pushpin. This will just give you a reference the pushpin you are ready have. I suspect you want to get the data for the pushpin which you can easily do by passing the cluster index into the GetDataByClusterIndex method. This will return an array of all the raw data that is in cluster. You can then grab the item you want and get it's original coordinate.
I am getting line latitude & longitude as
LINESTRING(1491215.4689647 6893983.2031826,1494163.0718675 6894785.7919795)
after seeing this solution.
how to get points return from OpenLayers.Control.DrawFeature
Now what I want to do is that I want to display start point & end point on my web page.
So how can I extract latitude & longitude from here so that I can show it in my page.
If your linestring is already in OpenLayers, there is no reason to convert it to WKT. Linestring geometry contains array of Points. You can access components of geometry in several ways, for example:
drawControls[key].events.register('featureadded', drawControls[key], function(f) {
// First point
var firstPointGeom = f.feature.geometry.components[0].clone();
// Last point
var secondPointGeom = f.feature.geometry.components[f.feature.geometry.components.length - 1].clone();
// Now you got geometries, let's create features from them...
var firstPointFeat = new OpenLayers.Feature.Vector(firstPointGeom);
var secondPointGeom = new OpenLayers.Feature.Vector(secondPointGeom);
yourVectorLayer.addFeatures([firstPointFeat, secondPointGeom]);
});
Pay attention - this works with LineStrings. Probably it's not necessary to go into detail about clone(), it's up to particular use case, whether you need it, or you can use just var firstPointGeom = f.feature.geometry.components[0];
Thats WKT format, you're looking at. You'll potentially need to reproject those coordinates to the target projection if they are not in the same projection. After than, you should be able ot ask openlayers for the points of any given geometry using the base geometry functionaily. Get the point array from the linestring instance and iterate over it. Make sure you know the right coordinate order for your projection / data model.
Hope that helps!
I know how to use an overlay projection to get a LatLng object, and then convert that single LatLng to pixels, using .fromLatLngToDivPixel()
However, .getBounds() returns a pair of LatLng coordinates. I've tried accessing it like it's an array (as in specifying index[1] for example) but that does not work. It doesn't seem to be an array.
Is there a way to convert the value from .getBounds() to pixel data?
However, .getBounds() returns a pair of LatLng coordinates. I've tried
accessing it like it's an array (as in specifying index1 for
example) but that does not work. It doesn't seem to be an array.
LatLngBounds is not an array, it's an object and the documentation shows you two methods to get the coordinates:
var NE = bounds.getNorthEast();
var SW = bounds.getSouthWest();
Those two methods return LatLng objects which you can pass to fromLatLngToDivPixel()
However, if you got your LatLngBounds object by reading map.getBounds() then you already know what the pixel values should be, (the corners of your map container DIV).
I currently have a implementation where some markers coming from JSON list is shown, on a particular area, Now I want to filter these marker depending upon some criteria, I have done the filtering part, and got the filtered list. Now to render this markers on the map again, The current implementation loads the js with a key again, also creates the GMap2 object and draws the list of marker on the newly created map, which is really annoying. I want map to be there and only markers to be added and removed from the map.
Any help is appreciated
You can use addOverlay and removeOverlay to add/remove markers from an already displayed map. See the examples here: http://code.google.com/apis/maps/documentation/overlays.html#Markers
var latlng = new GLatLng(lat, lng);
map.addOverlay(new GMarker(latlng));
You can make drawMap() and drawMarkers() as two separate functions. And after map has been created redefine drawMap to empty function like this:
drawMap = function(){}; After that only drawMarkers() will be executed.
Hope this is what you need. If not, provide some code.