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

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.

Related

How to find the centre of GPX data

Let's say I have some location data from a gpx file.
EG: [36.735058, -3.6843662, 13],[36.73534, -3.6841993, 12],[36.735455, -3.684072, 7],[36.735596, -3.6841817, 6],[36.735943, -3.6840394, 4]
I would like to find the center point using PHP so that when the points are rendered on a map, the map is centered at the center.
I suppose the the center point is some kind of average based on all the points.
Maybe there exists some king of algorithm to calculate the center.
The way I would approach this is to find the furthest North and South points and then find the point between them and do the same with East and West to find latitude and longitude of the center.
I haven't actually tried doing this this yet. I am wondering is someone else has already worked out the best way of finding a center point from a group of coordinates.
Yes, it works by finding the max North South Eat and West points.
Something like this
//WORK OUT THE CENTER POINT
$max_long = max($long_array);
$min_long = min($long_array);
$center_long = ($max_long + $min_long) / 2;
$max_lat = max($lat_array);
$min_lat = min($lat_array);
$center_lat = ($max_lat + $min_lat) / 2;

Mapping Nebraska school districts with D3 v4 - base layer not showing

I am having trouble mapping Nebraska school districts in D3 (v4). (See bl.ock here.) I can map Nebraska counties no problem, but the same code modified for school districts--and pointing to a school district TopoJSON file--gives me a blank page.
Here's how I created the JSON, based on Mike Bostock's excellent instructions :
curl "https://www2.census.gov/geo/tiger/GENZ2017/shp/cb_2017_31_unsd_500k.zip" -o cb_2017_31_unsd_500k.zip
unzip -o cb_2017_31_unsd_500k.zip
shp2json cb_2017_31_unsd_500k.shp -o ne_district.json
ndjson-split "d.features" < ne_district.json > ne_district.ndjson
ndjson-map "d.id = d.properties.GEOID, d" < ne_district.ndjson > ne_district-id.ndjson
geo2topo -n districts=ne_district-id.ndjson > ne_district-id-topo.json
And here's my projection:
var projection = d3.geoConicConformal()
.parallels([40, 43])
.rotate([100, 0])
.scale(8000);
Thanks for your help and apologies in advance for anything important I left out!
The issue is you haven't finished setting your projection parameters. You have rotate the map, which is how you should center a conic projection along the x axis. But you haven't centered the map on the y axis, it is centered on the equator. You
For a conical projection, you can do this one of three ways:
Center the map on a central latitude : projection.center([0,y])
You don't need to use .center with an x value because the map is already centered on the x by rotation, rotation and centering are cumulative
Rotate the map to a central latitude and longitude: projection.rotate([-x,-y])
On a conical projection the rotation on the meridian does not warp the map (generally), we rotate by the negative as we move the earth under us. This option does slightly distort the map relative to the other options - this may be preferrable.
Use the projection translation to center the map
The easiest way is to translate the result while automatically scaling (though you can do this manually too) with projection.fitSize or projection.fitExtent. These methods modify projection.scale and projection.translate. As with centering with .center, you need to keep your rotation - otherwise you'll get an odd tilt to the map.
These methods set translate and scale to appropriate values so that your map area contains the desired features:
var featureCollection = topojson.feature(ne, ne.objects.districts);
projection.fitSize([width,height],featureCollection);
These methods must take objects, not arrays, so we use the featureCollection, not the features as an array
Both methods take an array specifying the size to stretch a provided geojson object over:
projection.fitSize([mapwidth,mapheight],geojsonObject)
projection.fitExtent([[left,top],[right,bottom]],geojsonObject)
Here's an updated gist using fitSize.

Converting altitude to z-level (and vice versa)

When using ol3-cesium and the map is in 3d mode, calling map.getView().getZoom() returns undefined. This might affect setZoom as well.
I understand we are in a 3d world, so there are no z-levels as in the tiled maps. On the other hand, Google Maps calculates a z-equivalent when coming back grom 3d to 2d.
How can I convert from height to a z-equivalent? Any formula, taking into account the latitude and altitude, to get the z equivalent?
There's no easy formula to get a 2D "Z" value from 3D, because the 3D camera can be tilted, can see different levels of tiles in the foreground vs the background, etc.
For individual tiles however, there are specific known "Level" values from the imagery quadtree. You can see these in Cesium Inspector by clicking the little + next to the word Terrain on the right side, and then put a checkmark on Show tile coordinates. The coordinates shown include L, X, and Y, where L is the tile's level (0 being the most zoomed-out, higher numbers more zoomed in), and X and Y are 2D positions within the imagery layer.
I posted an answer on GIS SE that shows how to reach in and grab these tiles, the same way Cesium Inspector does, along with a number of caveats involved. You could potentially look for the highest-level visible tile, and use that as your "Z" value.
I know this is not accurate, but sharing in case this is of use to anyone.
I have moved to several altitudes in Google Maps, switching between the 2D and 3D maps, writing down the z or altitude shown in the address bar:
z altitude (metres)
----- -----------------
3 10311040
4 5932713
5 2966357
6 1483178
7 741589
8.6 243624
11.35 36310
13.85 6410
15.26 2411
17.01 717
18.27 214
19.6 119
20.77 50
21 44
With the above correspondences, I have approximated the following function:
function altitudeToZoom(altitude) {
var A = 40487.57;
var B = 0.00007096758;
var C = 91610.74;
var D = -40467.74;
return D+(A-D)/(1+Math.pow(altitude/C, B));
}
Based on your formula, the reverse conversion should be:
altitude = C * Math.pow((A-D)/(zoomLevel-D) -1, 1/B);

How to draw boundary around the address based on latitude amd longitude in Google Map

I have got a drop down of State and cities .
Upon selection of a State , corresponding cities will be displayed and once clicked on Go button , i am showning that particular city uisng Google Map.
Could you please let me know if how is it posible to show that area around dashed or dotted lines ??
I see that Poly line doesn't suit my requirement as it draws only one line .
Right now i have got only latitude and longitude obtained via
$(document).on('click', '.gobtn', function(event) {
$.getJSON('https://maps.googleapis.com/maps/api/geocode/json?address=' + address + '', function(data) {
latitude_res = data.results[0].geometry.location.lat;
longitude_res = data.results[0].geometry.location.lng;
}).done(function() {
});
});
This is my simple jsfiddle how i am showing map
http://jsfiddle.net/ZLuTg/1010/
Could you please let me know how to draw dashed / dotted around the boundary of latitude amd longitude ??
How to draw boundary around the address based on latitude amd longitude
If have a way to find the boundaries for the location you can use polyline to draw the border. Just close the shape, by joining the first point back to the last point.
If you don't already have the boundaries, according to the answer to this question Google Maps API V3: How to get region border coordinates (polyline) data? and others, google maps will not provide the boundaries for you.

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