Can I show a single country (masked out) in GoogleMaps? - google-maps

Is it possible to mask away neighbor countries in GoogleMap? In my case I just want to show Sweden on one view. On a second view just Norway, Denmark etc etc...
I know it is possible to draw polygon lines and fill them accordingly on to Maps API. Problem is that or the result sets get huge or the lines get very rough etc... Would be nice if GoogleMaps could deliver a country at the time without neighbors.
Does anyone know about a good coordinate database with country borders?

You can create very complex polygons in Maps without a drop in performance if you store them in KML file format and load them as KmlLayers. KML is an XML based vector file format for geo data. The beauty of using KML files in Google Maps is that they are rendered on Google servers into simple PNG files, matching the current resolution and bounding box of your Maps view at any time, no matter how complex the original polygon data is. So all complexity is handled server side at Google.
Here is a sample of a project, where I have used such a masking for one of the federal states of Germany. (The surroundings in this case are not fully masked away but only dimmed. But you can also mask them off just as easily by changing the alpha value of the fill color in the KML file.)
For a quick review KML files can also be loaded directly into the Google Maps public website (by entering their URL into the search field). Here is the KML file that I have used in the above project, loaded directly into Google Maps. (I have actually used a KMZ file here, but that is simply a KML file packed into a ZIP archive. You can pack and unpack it with normal ZIP tools.) BEGIN UPDATE 07/2015: Unfortunately Google has REMOVED the possibility to directly enter the URL of a KML/KMZ file into the search field of their public Google Maps when they launched its redesigned version in 2014. You can still use all techniques discussed in this answer but you cannot simply preview KML files by entering their URL in the search field anymore. If you need the KMZ mentioned above for further analysis, you can download it here. END UPDATE
Please be aware that Google implies a size limit to KML/KMZ files (currently 10 Mb uncompressed, 3 Mb compressed - details see here). If your KML files should be to large, there is software available to reduce the complexity (see examples here and here).
You will find free map data at many places on the Internet, most of them being in ESRI shapefile format. A great source for country maps is http://www.gadm.org/ with the big advantage of providing their data in KML/KMZ format too. If you should have to convert ESRI shapefiles to KML, have a look at the great (and free) OGR converter.
Please notice that KML files are only a solution if your polygons are static (like the border of Sweden is) and not depending on any user input. For dynamic polygons you will still have to use the Polygon class of the Maps API with the complexity restrictions that you have mentioned.

had a similar problem and managed it by combining gamps with fusion tables:
var table_id = 420419; //can be exchanged wit another table
var FT_Query = "SELECT 'kml_4326' FROM "+ table_id +" WHERE 'name_0' NOT EQUAL TO 'SWEDEN'";
var FT_Options =
{
suppressInfoWindows: true,
query: FT_Query
};
var layer = new google.maps.FusionTablesLayer(table_id, FT_Options);
layer.setMap(map);

Have you considered loading in a custom map?
I haven't used it myself, but hopefully that link could help you out a bit :)

Related

How to create a polygon on Google map using list of GPS location

I have a list of customer (GPS coordinates) for each salesman in excel file. I want to create a polygon in Google map that shows area of each salesman in map.
Is there any tool that shows my salesman area in the Google map ?
For the first step it is easier to use Google Earth.
To display data you need a google kml file.
Create a placemark, and use the Polygon.
More, see https://developers.google.com/kml/documentation/kml_tut
To display a kml in google maps, the file has to be located on a server reachable by an url.
Ffor goggle earth a local file on your disk is sufficient.
For this problem, you may want to use a concave hull algorithm. You can read more in depth at https://gis.stackexchange.com/questions/39205/converting-point-sets-to-polygon-boundaries
In JavaScript, you can use https://www.npmjs.com/package/concaveman.

KML file from Massachusetts GIS - display in Google Maps API

I've been pulling KML files from the Mass GIS service via their export feature:
http://maps.massgis.state.ma.us/map_ol/oliver.php
For example, a KML output of Population Density per Square Mile looks like this when exported:
http://evrkusd.fatcow.com/populationpersquaremile.kml
I try to add it to my Google Map and nothing shows up, although this code works fine with other kml files from other sources.
var NewLayer = new google.maps.KmlLayer('http://evrkusd.fatcow.com/populationpersquaremile.kml');
NewLayer.setMap(map);
I'm getting the idea that some of the kml tags are outdated or are not accepted by Google Maps API.
Is anyone able to get this file to work for them? Any ideas how I can (preferably easily) update this file to work with Google Maps? I'm going to be using multiple KML files like this, so I'm hoping I can do a fairly quick fix.
Your KML file is still too big:
http://www.geocodezip.com/geoxml3_test/v3_geoxml3_kmltest_linktoB.html?filename=http://www.geocodezip.com/geoxml3_test/populationpersquaremile.kml
If you click on the "load KmlLayer" button, it will show you the status return by attempting to load that file in KmlLayer:
Kml Status:DOCUMENT_TOO_LARGE
Your "partial" KML files are not valid xml, if I make the one you posted valid, it works with geoxml3, but the Google Maps API v3 KmlLayer still says it is too big.
See the documentation, the maximum fetched size of a raw KML file is 3M, your file is 7M+.
Fusion Tables can handle much larger KML than client-side maps, up 100MB total (though some limits apply to features). So that might be a solution.

Google Maps API draw; city, country, county, zip, state

I am developing a visualization based off google maps. There are a few requirements the most complicated being rendering different areas on a google map. I need to render a few different sets of polygons based on zoom so maybe country, state, zip etc. It seems as if I will need an array of latitudes/longitudes which outline each of these areas. Are there any resources for these?
I see something called fusion tables which allow users to implement kml shapes on the map. However those dont seem to meet my requirements as I will need to add thresholds to each polygon which is rendered.
Lastly would it be a bad idea to render a large number of polygons. Would you expect me to run into issues? Lets say I render all 50 states, would this cause problems?
This will all be done on the fly and rendered programatically. I will be building these polygons to be renderd based on the contents of a report so what I am rendering can change with each execution.
You can download many free shapefiles from the internet, for example # http://www.diva-gis.org/gdata. Maxmind has also a free world geo database. You can download my PHP class concave-hull # phpclasses.org and try to pull a shape from the Maxmind world geo database. You can also try my example # http://www.phpdevpad.de/geofence/. It also gives the concave-hull. Personally I can also recommend Geonames for a zipcode world geo database.
A Very Simply API exists for this query by zipcode,city,etc.. returns geoJson
https://www.mashape.com/vanitysoft/boundaries-io/overview
Image of the results in GooleMap

Download full KML from Google Maps

I have Google Map with about 1200 points. When I try to save it as KML or view in Google Earth there is only 1000 point. Is there a way (for example using some API) to download all points (I don't need KML - I just want coordinates with description - it may be in some other format)?
Map can be found here. When you save KML there will be no points from 6th page.
Apparently there is a 1000 feature limit on exports from My Maps:
Restrictions
#4. There is a 1,000 feature limit on a single My Maps export, and approximately 1,000
in displaying KML - so large maps wont particully benefit from this trick. Wont show an
error just the first 1000 points/lines/features.
See this post on the google map product forum for a workaround to export all the points, Barry Hunter also recommends (and I concur) using FustionTables if you need to display more points on a map (sounds like you don't need to display them on a map, just retrieve the data from your map).
Seems to work, here is a combined file displayed on Google Maps (goes up to 1193)
geoxml3 reports 1197: geoXmlDoc: Object -> placemarks: Array[1197]

How to improve KML performance

Hi
I'm having some issues with KML performance. At some times the KML markers only appear after a reload which may have to do with google caching the results. I think a better solution is needed perhaps something like displaying a total of markers for an area on a larger zoom level and then more detailed for levels that have more zoom. Is such a solution feasible and if so, how? Can you think of other ways how I can improve performance of my KML map? The links are http://www.koolbusiness.com and the KML file is http://www.koolbusiness.com/list.kml
I can load the KML file into maps.google.com with no problem however when trying to display it on my custom map the display sometimes won't load.
Thanks in advance for any suggestions.
UPDATE: I've updated to using a KMZ file with zip compression. The file is available via http://www.koolbusiness.com/list.kmz and the source and more info is available at http://montao.googlecode.com
don't know if it affects performance but it seems like you need to configure the mime types for kml files.
http://code.google.com/apis/kml/documentation/kml_tut.html#kml_server
Have you tried to compress the kml files as kmz files? You can do this with a zip program and just call the file kmz.
You repeat the style element in the placemarks but you can also create them under the doucment element and then just reference them with an id. http://code.google.com/apis/kml/documentation/kmlreference.html#style
I'm not sure if you've changed the KML yet to conform to some of the previous suggestions but...
The KML File seems to be pretty minimal which is good. I was going to suggest truncating the decimal points on the lat/lng.
You can compress like KML file to KMZ like the previous poster has mentioned. More information can be found here: http://code.google.com/apis/kml/documentation/kml_tut.html#kml_server You'll need to set up the KMZ MIME type on your server too.
You can reduce the amount of white space in your KML file. It seems to have additional spaces when not required...
You can configure your web server to send cached versions of the KML file... I'm not sure what kind of back end you're running though so I can't really give pointers. This might be a reason why the markers don't show. Google's server will time out your request if it takes too long.
As for your question about a solution to displaying total markers in an area for a zoom:
I was thinking you could for each zoom level, check the boundary of the map and then only display markers that have coordinates in that boundary. You'd probably have to write some kind of function that checks if it's in the boundary. I don't know of any way to retrieve the markers from the KML file as objects unless you manually parse the KML yourself using a client side parser.
To help determine why your markers don't load, try using FireBug to determine the requests to Google's servers. And see what kind of response is returning which might lead to more answers to your problem. I believe the one you should look for is KmlOverlayService.
Hope that helps.