Plotting two routes at same time with google maps api - google-maps

Is it possible to plot two routes at same time with Google maps api.
For Example
Route from city A to B
and Route from city C to D
In this case A,B and C,D are separated.
Thanks.

Here are two polylines on the same map; there doesn't appear to be a limit.
http://jsfiddle.net/Lqcde/3/
I didn't add the div panels (becomes too cluttered) but you can also show two sets of text directions. It's a bit confusing because both start points are shown as "A" and endpoints, "B". Add the following lines:
directionsDisplay.setPanel(document.getElementById("dir-1"));
directionsDisplay2.setPanel(document.getElementById("dir-2"));
<div id="dir-1"></div>
<div id="dir-2"></div>

Related

How to search for all points inside multi polygons which have intersect?

I am working with spatial object in MySQL. I have a table that saves the location of estate in database as "longitude" and "latitude", and I search for these estates inside of polygons that user requests. I am using the st_contains function in MySQL, like this:
select * from estate where ST_CONTAINS(GEOMFROMTEXT(region),POINT(plat,plon)));
In the code snippet region has this format:
"POLYGON((lat1 lng1,lat2 lng2,lat3 lng3,lat4 lng4,lat1 lng1),(lat6 lng6,lat7 lng7,lat8 lng8,lat9 lng9,lat6 lng6))"
Everything works well when polygons have no overlap with each other. However, if polygons have overlap, MySQL subtracts that overlap area and does not retrieve estates in the overlap area. I add this image for more explanation:
How do I make this search work correctly, even with overlapped polygons?
In MySQL, we have the type MULTIPOLYGON for this situation. You can see complete document in MySQL Spatial Data Types.
Your region will need to be defined like this:
"MULTIPOLYGON(((lat1 lng1,lat2 lng2,lat3 lng3,lat4 lng4,lat1 lng1)),((lat6 lng6,lat7 lng7,lat8 lng8,lat9 lng9,lat6 lng6)))"

Google static maps - group some points with custom marker

I'm using google static maps
I'm trying to display 2 groups (with option for more) of geo points.
Each group has different icon.
this url displays only the center icon with out others
http://maps.googleapis.com/maps/api/staticmap
?center=31.909440199627042,35.00186054020873
&zoom=14
&size=1200x1200
&markers=icon:http%3A%2F%2Ftinyurl.com%2F2ftvtt6|31.909440199627042,35.00186054020873|31.909440199627042,35.00186054020873
&markers=icon:http%3A%2F%2Ftinyurl.com%2F2ftvtt6|31.909440199627042,35.00186054020873|31.909440199627042,35.00186054020873&sensor=false
What am I doing wrong?
The problem is your request:
http://maps.googleapis.com/maps/api/staticmap
?center=31.909440199627042,35.00186054020873
&zoom=14
&size=1200x1200
&markers=icon:http%3A%2F%2Ftinyurl.com%2F2ftvtt6|31.909440199627042,35.00186054020873|31.909440199627042,35.00186054020873
&markers=icon:http%3A%2F%2Ftinyurl.com%2F2ftvtt6|31.909440199627042,35.00186054020873|31.909440199627042,35.00186054020873&sensor=false
First: why do you have 2 markers fields?
Then: your markers are at exactly the same locations... So you see only 1 pin.
If I try the following (removed the 2nd markers and changed a value) I see 2 pins:
http://maps.googleapis.com/maps/api/staticmap
?center=31.909440199627042,35.00186054020873
&zoom=14
&size=1200x1200
&markers=icon:http%3A%2F%2Ftinyurl.com%2F2ftvtt6|31.909440199627042,35.00186054020873|31.909440199627042,35.0000
&sensor=false

intersection of border and route in google maps

When I have a specific area of the operation (like city or town) but would like to travel from point A in that area to point B outside of that area how can I check the exact point of the intersection of a route and border of area on google map?
ts like A -> [ C ] -> B
where A and B are start and finish point of route
and C is exact point for route / border - so i need distance (A;C) and then distance (C;B) with information where C is (intersection of route and border)
its urgent for me,
cheers, Marcin

Two routes with the same direction?

I have the next routes:
The red one is goes from A to B, the blue one goes from A' to B' and the green one goes from A'' to B''. I have the lat/long for A,B, A', B', A'' and B'' (I'm using Google Maps API) and I want to know if there is an algorithm to determinate if two routes have the same direction.
For example, in the picture, the red and blue route have the same direction.
Find the bearing of B from A. Movable-type's page is the standard reference.
However you can also use the geometry library in Google Maps API v3:
var a = new google.maps.LatLng(...);
var b = new google.maps.LatLng(...);
var bearing = google.maps.geometry.spherical.computeHeading(a,b)

How to display two or more markers on the same location?

I have a question about the GOOGLE MAP API. If you have more than two data that share similar address, how do you show the Pins Drop on the same address?
Example
You have data such as the following:
Name=>Ray | Address=>Melon Park, California, USA ;
Name=>John | Address=>Melon Park, California, USA ;
Name=>Steve | Address=>Melon Park, California, USA
You want to display 3 Pins Drop for the similar address on Google Map.
The post linked above has some good advice. Your options are really:
Offset the markers slightly, so instead of displaying them all on the same they are all on really close to each other. Just add add or subtract small delta to each of them.
Use different icons for each location. If you know the maximum number of markers that could overlap (like 4?) at the same location, you could make your own rotated icons, so instead of pointing "down" in the typical teardrop shape they could point left, right, or up.
Handle the data overlap in your infowindow / UI.
Adding small delta will work like this (this script is written in PHP):
$random_num_lat = .00065 * mt_rand(1, 10); // delta to the lat value added
$random_num_lng = .00065 * mt_rand(1, 10); // delta to the lon value added
$lat=$row['lat']+$random_num_lat;
$lon=$row['lon']+$random_num_lng;
//now in loop it will be three `enter code here`marker display seperate to each other
while ($row = mysql_fetch_array($query)) {
echo ("addMarker($lat, $lon,'<b>$name</b><br/>$desc1');\n");
}
I achieved this using a "spiderfier" to "spiderfy".
There is a GoogleMaps v3 Spidifier available here (demo).
Leaflet.js can also load GoogleMaps v3 and has a beautiful clustering spidifier available here (demo).
Note: Following is a more of hack than a solution:
Write an algorithm that checks for repeated coordinates in array.
When a duplicate is found, add a small value such as 0.000001 to the found coordinates.
Note that the smaller the value the more you have zoom in to see the difference.