Comments (13)
the trick is to realize that each map field can have a number of different markers in it.. assuming you just have one marker in the map field it would be something like this
{% set options = { id: 'map', width: '400px', height: '300px' } %}
{{ craft.googleMaps.map(options) }}
{% for marker in entry.yourCustomMapField.getMarkers() %}
{% set lat = marker.lat %}
{% set lng = marker.lng %}
{% endfor %}
{{ craft.googleMaps.center('map',lat, lng) }}
Iif you just want to output the map for an entry is to use the field directly so just this, and it will automatically center on that marker
{% set options = { id: 'map', width: '400px', height: '300px' } %}
{{ craft.googleMaps.map(options) }}
{{ craft.googleMaps.data('map', entry.yourCustomMapField) }}
from google-maps-for-craft.
Is this list of variables documented somewhere "marker.lat" and "marker.lng"?
from google-maps-for-craft.
I dont think they are fully documented yet. I just went into the plugin files, in "models" theres GoogleMaps_MarkerModel and GoogleMaps_MapDataModel. in both of those look for the "defineAttributes()" function that will list the properties of the model
from google-maps-for-craft.
ahh and he also has it written out in the wiki although there appears to be a typo as it says latitude vs lat
https://github.com/objectivehtml/Google-Maps-for-Craft/wiki/Template-Reference#marker
from google-maps-for-craft.
Got it. I'll look there. Thank you! Was pulling my hair out yesterday trying to accomplish what I needed to accomplish for this project. Still having weird issues.
from google-maps-for-craft.
When I try this code on a location's detail page with my custom field name added, I get no output.
{% for marker in entry.map.getMarkers() %}
{% set lat = marker.lat %}
{% set lng = marker.lng %}
{% endfor %}
{{ lat }} {{ lng }}
Do you?
from google-maps-for-craft.
yup… is map your map fields handle?
Have you turned on geocoding ?
Geocoding has to be enabled in the plugin settings and you note which fields make up the address to geocode or on the field settings if you want it to geocode it as you edit the entry.
from google-maps-for-craft.
Yes, "map" is my field's handle.
GeoCoding is on in plugin settings and I'm running the latest version #0.7.1
The fields that make up the address are set at the plugin level and the field level and the entry's marker is correctly set and saved in the DB.
I can get the map to show up on the detail page using this code but I want to control the zoom level and cannot do that using map() or data():
{{ craft.googleMaps.map({
id: 'locationmap',
width: '385px',
height: '300px',
options: {
scrollwheel: false
}
}) }}
{{ craft.googleMaps.data('locationmap', entry.map) }}
from google-maps-for-craft.
just use the zoom settings
https://github.com/objectivehtml/Google-Maps-for-Craft/wiki/Template-Reference#zoom
so add this
{{ craft.googleMaps.zoom('locationmap', 12) }}
from google-maps-for-craft.
I have tried that code and every other possible way to control the zoom. That code doesn't override the maps default zoom at all for me.
What works is setting "fitBounds: false" on map()... but then I need to get the marker's lat and long in order to center and zoom the map out... hence my question about how you get data out of the "geocoding'.
Will keep trying.
from google-maps-for-craft.
NOTE: I can get lat & lng printing out in the template if I move the variables inside the for loop:
{% for marker in entry.map.getMarkers() %}
{% set lat = marker.lat %}
{% set lng = marker.lng %}
{{ lat }} {{ lng }}
{% endfor %}
from google-maps-for-craft.
ALAS... This finally worked!
{% for marker in entry.map.getMarkers() %}
{{ craft.googleMaps.marker('locationmap', {
lat: marker.lat,
lng: marker.lng,
fitBounds: false
}) }}
{{ craft.googleMaps.zoom('locationmap', 13) }}
{{ craft.googleMaps.center('locationmap', marker.lat, marker.lng) }}
{% endfor %}
Keith, a sincere THANK YOU!
from google-maps-for-craft.
Yup, thanks the way to do it. Thanks for the help Keith. Out of town on vacation this week with limited access to Internet.
from google-maps-for-craft.
Related Issues (20)
- Error when Google maps can't find the location HOT 2
- Folder Name HOT 2
- Polgyon Color Options HOT 2
- Force search within specific country HOT 1
- Create map from front-end form HOT 10
- Address Fields doesn't work if the field is of type Address HOT 2
- Geocoder seems to run each time, despite saved locations HOT 1
- Required setting not working for map field HOT 2
- Customising Styling for Routes / Polylines
- Search: show nearest entry on map HOT 1
- Remove googlemaps isSecure because it is not necessary
- Info Window on a PolyLine HOT 1
- Test for No Results HOT 1
- Bug on Route and setting map ID
- API Key HOT 1
- Centering map and setting marker with dynamic fields
- Insecure file transfer on reverse proxy server because protocol is being set incorrectly
- GoogleMaps_TemplatesService.php data function looks to be broken
- This project dead? HOT 4
- Adding Marker
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from google-maps-for-craft.