I don't see any option to put a pin at the default location for the Google Maps web part. How do I do this? Thanks!
How to add a pin at the default location for a google maps web part in Kentico 9?
340 Views Asked by anonymouse AtThere are 3 best solutions below

Assuming you've filled in the "Default Latitude" and "Default Longitude" fields and you've unchecked the "Hide if no record found" checkbox, the pin will show automatically. If you have not unchecked that box and there are no records, the webpart will be hidden.
** EDIT **
Based on answers from the OP, using the Static Google Maps and having the lat and long fields filled in with valid coordinates, it will auto populate the pin.
Also there were issues with the Google Maps API which were resolved in v9 hotfixes 32 and 36 so if you can apply those hotfixes it should help to resolve the problem.

The "Default latitude" and "Default longitude" settings of the "Google maps" webpart are not used for setting a default pin, but for centering the map at the given point on page load.
You could use JavaScript to add a pin to the map.
- Set the "Default latitude", "Default longitude" and "Detailed view scale" properties on the "Google maps" webpart
- Inspect the webpart on the live view of the page, and find the ID of the container. The container ID is the actual ID of the map instance.
Use the
addGoogleMarker
JavaScript function to add the pin to the map, using the ID obtained in step 2.
The signature of the function is:
addGoogleMarker(map, latitude, longitude, title, content, zoom, iconURL)
To do this, add a "Javascript" webpart, with the script page location set to "Startup script", and the "In-line script" property set to the following:addLoadEvent(function() { var mapInstance = p_lt_ctl00_GoogleMapsWithUniqueID_map; var latitude = {%WebPart.GetValue("GoogleMapsWithUniqueID", "Latitude")%}; var longitude = {%WebPart.GetValue("GoogleMapsWithUniqueID", "Longitude")%}; var zoomScale = {%WebPart.GetValue("GoogleMapsWithUniqueID", "ZoomScale")%}; addGoogleMarker(mapInstance, latitude, longitude, '', '', zoomScale, ''); });
Alter the script to contain the correct map instance ID (obtained in step 2 - in this example, it is
p_lt_ctl00_GoogleMapsWithUniqueID_map
), and the Google maps webpart control ID for thelatitude
,longitude
andzoomScale
variables (in this example, it isGoogleMapsWithUniqueID
).
This solution might cease to function correctly if you alter the layout, or move the webpart. The ID of the map is hardcoded, and the solution would be to use jQuery to dynamically locate the map and obtain the ID.
The IDs are not stored in any global variables, hence the solution of hardcoding the ID.
Define "Default Location", are you talking about the user's current location? Or some location you determine?
If it's the user's default location, you would have to employ javascript (as this logic pretty much has to be done client side, you can use MaxMind GeoLocate if you wish to do server side, but that's another topic).
Check this example out, you would just add some javascript like this and point it to the map you are generating with Kentico.
https://developers.google.com/maps/documentation/javascript/geolocation