Map Location Field
This is an open discussion with 37 replies, filed under Extensions.
Search
This is a new field type which is a tie in to Google Maps. It allows you to mark a location and, upon saving, will store the longitude and latitude coordinates. Be sure to read the README.txt
file as it contains important information for getting the field installed correctly.
Many thanks to Airlock for funding the development of this extension and choosing to release this under an open source license for all to freely use.
Note: This extension requires Revision 4
Download: extension-maplocationfield-1.0.zip
awesome
Thank you, Airlock!
how do you get a google maps api key?
There is a link in the preferences to the google maps page. Just follow the instructions on the google site.
for all those as incompetent as myself, here's a link to sign up for a key if you do not have on already:
This is awsome! Almost exactly what I was looking for. I have one suggestion, wouldn't it be a good function if you had one or two input fields for manually entering exact coordinates (that would update the map view) if you don't have a good reference in the map view (lets say you're out on a hike or something)?
Or would it be better to just use another text input field and override the Google Map coordinates if there is something entered in my own field?
Another thing, I have some problem with changing the default location. When I save my section it always revert to "Brisbane, Australia". Anyone else have the same issue?
If you disable Javascript, you should see that the field is just a input field. It's a bit of a workaround, but you could either a) disable JS or b) remove the JS code from the admin to manually put your data in the system.
When we get more time, we may update the extension.
First off, great extension. Thank you.
Secondly, does the ability to add markers not function?
I've tried multiple ways including pastie:
<script type="text/javascript"> google.load("maps", "2.x"); var map; function initialize() { map = new GMap2(document.getElementById("map")); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); map.setCenter(new GLatLng(<xsl:value-of select="entry/google-map"/>),13); map.addOverlay(addInfoWindowToMarker(new GMarker(new GLatLng(<xsl:value-of select="entry/google-map"/>)),"Garde enfants, personnes agées, animaux domestiques",{})); } google.setOnLoadCallback(initialize); </script>
Got it to work after some more trial and error. The following is what I did (or pastie)
<div id="google-map"> <script type="text/javascript" src="http://www.google.com/jsapi?key=GOOGLEMAPAPIKEY"></script> <script type="text/javascript"> google.load("maps", "2.x"); var map; function initialize() { map = new GMap2(document.getElementById("map")); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); var center = new GLatLng(<xsl:value-of select="entry/google-map"/>); map.setCenter(center, 13); map.addOverlay(new GMarker(center)); } google.setOnLoadCallback(initialize); </script> <div id="map"></div> </div>
Thanks Alistair
If you were just wanting the co-ordinates output to the Head of the Article could you use something like:
<meta name="ICBM" content="<xsl:value-of select="entry/map"/>" />
I know this contains "illegal attributes" but is there simple way of achieving this?
@pertoyra - In Section > Article
just fill in the Default Marker Location to were you want it to initially centre.
The below:
<meta name="ICBM" content="<xsl:value-of select="entry/map"/>" />
Should be:
<meta name="ICBM" content="{entry/map}" />
Thanks Allen, that should do it - but so far no show.
I have tended to use "new google.maps." instead of the older "new GMap2" but yes, they are both meant to still work - shame I can't get it to work here...
If anyone is interested, I wrote-up a bit about GeoBlogging (using an XML file and Textpattern) here: http://spotthehall.com/geoblogging - there may be bits that could be pulled into this scenario.
Does anyone know how to tweak this extension to make it more dynamic? In other words, right now when you add a "Map Location" field to a new section, you enter in your Default Location there and when you go to publish in that section, it shows your default location with no way to change it... unless you change it in the section area.
Is there a way to use data from one text field in the same section that you are using a "Map Location Field"?
For instance, I have a section called...
Stores (with the following fields)
- Store Name (Text Field)
- Store Description (Textarea)
- Store Address (Text Field) --> which would be an address like 123 Test Dr, Anywhere, NY.
- Store Map (Map Location Field)
Is there a way to take the "Store Address" and generate the "Store Map?" And if there is now "Store Address" listed, then it will use the "Default Map Location." Does anyone know how to attack this?
Right now, I think I'm missing how to use the Map Location field, because it seems to just post the "Default Map." So it seems really static.
Does that make any sense?
Also, I've been combing through Google Maps API... and I'm lost. I think I'm just not getting it. Any help would be most appreciated.
Thanks so much for your time! BZ
Is there a way to take the "Store Address" and generate the "Store Map?"
Try adding the following at line 18 of maplocationfield/assets/gmap.js
:
map.enableGoogleBar();
I think that's all you'll need to enable searching, but I'm equally confused by the API reference. Alternatively, if you disable Javascript, the map location field falls back to a text input field, which you could paste the desired coordinates into.
I like your idea of using/converting addresses, and we could probably put better support for this in a future version of this field (along with multiple coordinates, and many other features). When the time comes to port this to RC1+, I'll put a lot more effort into learning the GMap API.
Right now, I think I'm missing how to use the Map Location field, because it seems to just post the "Default Map." So it seems really static.
Basically, the Map Location field's default location is found via a call to the API. That call returns the co-ordinates, and then those co-ordinates stored in the database. When you create a new entry that contains that map field, the default location co-ordinates are used to pre-populate a text field (Should you be editing, instead of using the default location, it will be whatever was saved). The JS grabs that and replaces the text field with the map. The user can then choose the location they want by moving the marker (which was placed by the JS at the location specified by the text input). Moving the marker will update the co-ordinates in the hidden text field.
Is there a way to take the "Store Address" and generate the "Store Map?" And if there is now "Store Address" listed, then it will use the "Default Map Location."
If I understand this correctly, you're after a map location field that allows the user to type in the location they want, rather than mousing around and dropping the marker? Maybe you could modify the JS in that case.
Although I'm not overly familiar with the Google Maps API, if you have the full address, why do you need a Map Location field? Couldn't you just use the address information on the front-end in combination with the Google Maps JS API to grab the co-ordinates and then show the map?
Scott and Alistair -
Thanks for responding to my question.
Although I'm not overly familiar with the Google Maps API, if you have the full address, why do you need a Map Location field? Couldn't you just use the address information on the front-end in combination with the Google Maps JS API to grab the co-ordinates and then show the map?
That's what I'm trying to figure out. I'm having a hard time figuring out what Google Maps API method will turn my address into coordinates which ultimately publish a map of that location for me. If y'all have any insight for me that would be awesome. Unfortunately, my scripting skills stink. I definitely need to improve in that area.
edit, what i previously wrote was incorrect.
Just found a quick gotcha with the new Google Static Map API (http://code.google.com/apis/maps/documentation/staticmaps/).
When requesting a location using the lat/lng, it was failing and all I was receiving was a blank image; turns out the problem was a leading space on the lng.
To fix it I just edited the gmap.js (line 23) in the extensions folder to remove the space in the input :)
Problem solved.
Create an account or sign in to comment.
A new Extension, “Map Location Field” is now available for download. Comments and feedback can be left here but if you discover any issues, please post it on the issue tracker.