Git Product home page Git Product logo

simplemap's Introduction

Maps

Maps

A beautifully simple, yet deceptively powerful, Map field that works out of the box with no setup or API tokens needed!

Configure the map field to only show the features you want; hide the address, show latitude / longitude, or hide the map entirely. Choose from 4 geocoding services, 3 geolocation services, and 24 map tilesets!

Maps offers full multi-site support, compatibility with Matrix, SuperTable, and CraftQL, and the ability to search by location and sort by distance.

Maps Field

Searching

Mini Map

Maps offers a mini map field that fits perfectly in a Super Table without taking up a lot of space!

Mini

Map Tiles and Geo

Maps supports the following map tiles:

Wikimedia
Wikimedia
Wikimedia
Wikimedia
OpenStreetMap
OpenStreetMap
OpenStreetMap
OpenStreetMap
Carto (Voyager, Positron, Dark Matter)
Carto
Carto Voyager Carto Positron Carto Dark Matter
Voyager Positron Dark Matter
Mapbox (Outdoors, Streets, Dark, Light)
Mapbox
Mapbox Outdoors Mapbox Streets Mapbox Dark
Outdoors Streets Dark
Mapbox Light
Light
Google Maps (Roadmap, Terrain, Hybrid)
Google Maps
Google Roadmap Google Terrain Google Hybrid
Roadmap Terrain Hybrid
Apple MapKit (Standard, Muted, Satellite, Hybrid)
Apple MapKit
MapKit Standard MapKit Muted MapKit Satellite
Standard Muted Satellite
MapKit Hybrid
Hybrid
Here (Day, Day Grey, Day Transit, Reduced, Pedestrian, Terrain, Satellite, Hybrid)
Here
Here Day Here Day Grey Here Day Transit
Day Day Grey Day Transit
Here Reduced Here Pedestrian Here Terrain
Reduced Pedestrian Terrain
Here Satellite Here Hybrid
Satellite Hybrid

And these geocoding services:

And these geolocation services:

Documentation

For full documentation visit the Maps Ether Docs.

simplemap's People

Contributors

alexjcollins avatar bhartmancr avatar bighoho123 avatar cballenar avatar cornernote avatar ctigelaar avatar davidwebca avatar dependabot[bot] avatar dwheeldo avatar idontmessabout avatar jamesedmonston avatar markhuot avatar maxdmyers avatar pascalminator avatar peet86 avatar roelvanhintum avatar saboteur777 avatar samhibberd avatar simondotwhite avatar simoneast avatar tam avatar tomkiss avatar zae avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

simplemap's Issues

Works in CP, how to embed into frontend?

Nice plugin! I am able to play with it in the control panel and it looks great. But what should I add to the frontend templates to insert it there?

I tried:

  1. Created a field called simplemapfield
  2. Added it to a section, (About page of a demo site)
{{ simplemapfield }}
<simplemapfield></simplemapfield>
{% embed "simplemap/templates/map-fieldtype.twig" %}

I even tried copy-pasting the contents of map-fieldtype.twig into the about page template. Obviously I am undereducated in handling this part of the code. Any help would be appreciated.

Searching and Sorting breaks if Google can't find the location

Searching and Sorting breaks when looping through entries if Google can't find the location.

So if I entered some gibberish (e.g. "dsfdsfdsfdsfds"), then it returns an error, rather than just no results.

It returns a CDbException error, complaining about Unknown column 'distance' in 'order clause'.

{% set locations = craft.entries.googleMap({
    location: 'dfdsfdsfdsdfsd',
    radius: 50,
    unit: 'mi'
}).order('distance') %}

{% for location in locations %}
<p>{{ location.title }} - {{ location.googleMap.distance }}</p>
{% endfor %}

Not remembering pin placement after dragging

I'm getting an issue where if I put in a postcode to get near where I want and then I drag the pin to the exact location (which is still be in the same postcode area), but on saving it reverts to the default postcode lat/lng. Sometimes the postcode area can cover several square kilometres and I need to be able to be precise.
In a particular case there is no second set of numbers for the postcode (Donovan Ln, Taunton TA4, UK) so the area is very large for TA4.
I have 2 separate fields for lat and lng that are using the Preparse plugin to auto populate from the simplemap field data. They store the correct lat/lng from the pin placement after dragging, but on reopening the entry after saving the pin moves back to the default postcode location and then updates the Preparse fields to that.

Q: How do I display the actual map on the front-end?

Hi there,

This plugin looks like what I need: a simple, straight-forward Google Map field. I don't need all the bells and whistles that so many other plugins seem to have.

Having said that, I'm a little concerned as I haven't found a way to display my map on my entries' template. Is this plugin just for extracting data from the location set in the backend, or am I able to show the map itself?

Sorry if this is a completely noob question... I'm just getting started with Craft :)

Thanks!

Some seaches not returning results

Hi,
Not sure if this is plugin or Google related.
I have location field set up. I have a search field on my front end that queries this location field. It's mainly fine, but I have noticed that it will only return results if the search string matches what the Google address autocomplete would be.
For example, when I search for "Winchester" I get no results, but if I search for "Winchester, United Kingdom" I get the relevant results.

Any ideas?

Isn't working for me inside a matrix

I've added this as a field inside a matrix block, and it's not working when referenced in the template like this:
{{ block.googleMap }}

It gives this error:

Object of class Craft\SimpleMap_MapModel could not be converted to string

However, referencing individual elements works fine, eg {{ block.googleMap.lat }}

Am I using it wrong?

Google API key

Since version 1.5.0, the geocoding is done via a curl. This means previously generated Google API keys with a browser restriction won't work anymore as the request is now a server request opposed to a browser request (when using Javascript).

This should be mentioned in the CHANGELOG as a breaking change since the feedback in the CP is still there (it uses the JS library) but the address parts won't get saved anymore (it uses a server request).

I would also recommend using different API keys for front & CP requests as the key used by SimpleMap has no restrictions on it. It is used for JS and server requests and you can only add 1 restriction per key in the Developer Console.

Is there a way to display distance?

Hi, thank you for this great plugin! I was wondering if there is a way to display the distance of each location relative to the search point. I'm able to sort by distance but it would be great to be able to display this distance in the template, as well.

Thank you!
Brady

Simplemap and Neo

Hi,

I've come across a minor edge-case bug when dealing with neo and simplemaps. If you have a simplemaps field that is both on an entry and inside a neo field on the same entry, the first field fails to load the google map whilst the one inside the neo field is fine... If that makes sense.

Short Names

This returns nothing when using {{ myMapField.parts.country_short }} is this expected behavior? {{ myMapField.parts.address }} returns the full address.

CP errors on Saving address on publish page

Craft 2.6.2972
SimpleMap 1.5.0

I've added a field to a single and when I attempt to save the entry I get errors. Removing the field and the errors go away. This does not change whether an address has been added to the field or not.

Errors on publish are:

array_key_exists() expects parameter 2 to be array, null given

D:\path\to\craft\plugins\simplemap\services\SimpleMapService.php(232)

220         if (!$browserApiKey) return [[], $address];
221 
222         $url = 'https://maps.googleapis.com/maps/api/geocode/json?address='
223                . $lat . ',' . $lng
224                . '&language=' . $this->_formatLocaleForMap($locale)
225                . '&key=' . $browserApiKey;
226 
227         $ch = curl_init();
228         curl_setopt($ch, CURLOPT_URL, $url);
229         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
230         $resp = json_decode(curl_exec($ch), true);
231 
232         if (array_key_exists('error_message', $resp) && $resp['error_message'])
233             SimpleMapPlugin::log($resp['error_message'], LogLevel::Error);
234 
235         if (empty($resp['results'])) return [[], $address];
236 
237         $result = $resp['results'][0];
238         $formattedAddress = empty($address)
239             ? $result['formatted_address']
240             : $address;
241 
242         foreach ($resp['results'] as $res) {
243             if ($res['formatted_address'] == $address) {
244                 $result = $res;

OVER_QUERY_LIMIT

I'm using this (great) plugin in a Matrix for a client, one row for each office they have. If we add more than three rows there is a console warning;

Geocoder failed as a result of OVER_QUERY_LIMIT

We can always solve this without using Matrix, but I thought I'd give you a heads up on this.

location param only works with lat/lng values

Hi guys. This plugin is going to really useful on a site I'm building but I can't get it working right. For some reason searching/sorting only works when I pass in lat/lng values, but not when I pass in a string like 'Manchester, UK'. In the latter case I don't get an error, I just get a list of all entries, when it should only return about 5.

So this works:

{% set entries = craft.entries.serviceCentreMap({ location: ({'lat': 53.480759, 'lng': -2.242631}), radius: 10, unit: 'mi' }).order('distance') %}

But this doesn't:

{% set entries = craft.entries.serviceCentreMap({ location: 'Manchester, UK', radius: 10, unit: 'mi' }).order('distance') %}

Any ideas?

Request: Add short_name to parts

Can you add the short_name from Google's address_components that are returned? This will allow me to display abbreviated states here in the US. For example, using .parts.administrative_area_level_1 returns California, I'd like to display it as CA.

Thanks!

Performance Issue (Waiting for table metadata lock)

Hi There,

We have been running into some performance issues on a high traffic site and have caught some queries in MySQL causing Apache processes to backup and subsequently crash.

Our hosts (Arcustech) worked with Brad (Craft) to try and work out the cause and suspect it might be coming from one of the queries generated by simple maps.

I thought it would be good to share our findings and ask if you have run into anything similar or have any ideas of how to debug / fix the issue.

I worked for about 30 minutes today with Brad Bell here in the Craft CMS offices in Bend, OR. and we found a few things.

First the query I caught in full this morning that was running multiple times at once on the MySQL server this morning when we restarted mysql to clear them out, is in the text file I have attached.

Brad took a copy of your production database and installed it on his local test system here in the Craft office, and in Navicat ran the above query directly against your database copy. It took his system here over 4 minutes to run the above query, and looking at an analysis of what the query had to do there were well over 200 million requests to mysql to read the next row in tables. This obviously is both slow and resource intensive, and is clearly triggered by the simplemap plugin.

Unfortunately looking through both your craft templates and the simplemap code Brad could not pinpoint exactly what maybe creating the 8 LEFT JOINs to the craft_relations table which itself has 277k+ entries.

The conclusion is the site slowdowns are not directly related to anything Craft CMS core code wise or the server configuration. With that said, if the SimpleMap plugin developer can maybe supply some feedback on the plugin usage, the amount of data you are running the above query against, and possibly some alternatives to making it more optimal.

I know this does not solve the issue, as we are still unsure exactly what feature or search on your site will generate the above query, but at least we hope it leads you and/or your developer towards a path of finding out.

Please let us know if you have further questions, and at least from a coding standpoint you can reach out to Craft support too as they have background at looking at this now too.

sql-query.txt

Many thanks,

Sam

Won't save after geo locating

I enter a postcode in the search bar, select the result from the popup, then when I click Save nothing happens. But if I select "save and continue editing" it saves.

I've tried this a few times and sometimes if I put in a new postcode it works first time. But if I then put in the original postcode it doesn't.

There are no errors or warnings in the console.

Map fails when used in globals

The following code returns a Cannot read property 'getElementsByTagName' of null error when used in a field in Globals (with no #tabs element).

// Re-draw map on tab change
    [].slice.call(document.getElementById('tabs').getElementsByTagName('a')).forEach(function (el) {
        el.addEventListener('click', function () {
            var x = self.map.getZoom(),
                c = self.map.getCenter();

            setTimeout(function () {
                google.maps.event.trigger(self.map,'resize');
                self.map.setZoom(x);
                self.map.setCenter(c);
            }, 1);
        });
    });

Usage from another plugin

I'm creating entries programmatically that have a SimpleMaps field. I have latitude and longitude data and I want to add that to the entry when I create it.

This code doesn't work, but it's basically what I'm trying to do.

$entry->setContent([
    'simplemap_field' => [$lat, $long],
    'some_other_field' => 'some text',
]);

I'm guessing I need to create a simpleMap object first then add that to my entry.

$sm = New SimpleMap([$lat, $long]);
...
    'simplemap_field' => $sm,
...

Can you point me toward some documentation covering this?

Invisible map when in a secondary tab

When I include the simplemap field type in a secondary tab in the field layout for the section the map is invisible (just grey box). The location bar updates if I drag the pin around, just no map tiles visible.
If I put the field on the primary tab it works fine.

I've had similar problems before with Google maps in ExpressionEngine where it didn't work in hidden tabs. The solution was that the map needed to be redrawn and needs some js to do it.

Submitting to Simplemap from Front End form

I currently have a front end form that is passing lat/lng values to Simplemap. The only issue is that when I save this, it only captures the lat and long and therefore the address and parts are not generated. Any idea if it would be possible to achieve this? I'm thinking it would work similar to Josh's Feedme integration that completes the rest of the data from the supplied lat/lng, presumably after save?

Really like this plugin so would be great if this can be achieved! Thanks.

Not working in IE11 (probably dispatchEvent)

Hi,

In IE11 the plugin is not loading in Craft CMS. We did some researching and think it is because of the dispatchEvent in:

SimpleMap.LoadGoogleAPI.LoadMapsApi = function (key, locale) { google.load('maps', '3', { other_params: 'libraries=places&key=' + key + '&language=' + locale.replace('_', '-') + '&region=' + locale, callback: function () { document.dispatchEvent(new Event('SimpleMapsGAPILoaded')); } }); };

The error message is: "Object doesn't support this action"
Could you fix this?

Upgrade to 1.6 doesn't update non-translatability for existing location field values.

I just upgraded from 1.5.1, went into some of my entries where location fields (set as non-translatable) were previously saved, and the locations didn't appear. Going into the database and manually changing the ownerLocale to NULL made the field values show up again when editing the entries. this seems like a pretty big deal, as the casual observer will see a bunch of fields that are suddenly empty after the upgrade. Fortunately I didn't have too many and had the wherewithal to check the DB and figure out what was going on. Let me know if you need more info.

Search results different on local env to live env

Hi,

Not sure if this is a Simplemap issue, but we're having some strange behaviour. Working on a site locally, I've a search form that searches entries based solely on the location field. All works fine. For example, a typical search with a radius gives 20-30 results.
We then pushed this to staging server and the search now returns zero or 1 to 2 results. Exact same database copied down from the live/staging server to local. Always works on local. I'm at a loss on what to check?

Is it possible to query locations based on information from a part of the address?

This might be my neophyte showing with Craft ElementCriteriaModel but I figured maybe this would be simplemap specific. Is it possible to do a query of all items within a section based on a value within [field].parts? Something like:

{% set members = craft.entries.section('members').addressField({
  country: "United States"
})

No Multilanguage?

I just saw that on a multilanguage site the locality is not displayed on the secondary language.

That's the code:

{% for loc in entry.gigLocation %}
   {{ loc.title }}
   {% if loc.location.parts.locality is defined %}
      {{ loc.location.parts.locality }}
   {% endif %}
{% endfor %}

Primary language German prints:

Dampfzentrale Bern

Secondary language English prints:

Dampfzentrale

Why is that? Ist that a bug? The locality should be language independent I think.

Importing to a Simplemap field...

Hi,

Love this map fieldtype, it's super useful enabling the outputting of parts.
I'm currently attempting to import a load of entries that contain lat/lng data into a Simplemap field using the Feedme plugin.

If I import that following :
{"lat":"{latitude}","lng":"{longitude}","zoom":"14","address":"", "parts":""}
I get the lat/lng imported into the Simple map field, the marker shows in the correct location, however, the address & parts are left blank. Is there anyway to make Simplemap update these values once it's gotten the lat/lng passed through to it?

Realise it's a long shot, but would love to get this working! Thanks!

Error at save new user

Very nice plugin! Keep up the good work!
When I use the field in a User profile it won't save:
in_array() expects parameter 2 to be array, null given

Output Google Maps API key on front-end

I just wondered if it was possible to get the API Key used by the settings out on the front-end in your twig templates? It'd be really useful, rather than having to store it in a separate field for use in your templates.

All the best,
Steve

Add ability to use simple map fields as "title"

When trying to use the value of the simplemap field as the title of an entry i get a "cannot convert simplemap object to string" because afaik there is no defined behaviour that handles this scenario.

Feature request:

When trying to use the value of the simplemap field as the title of an entry, make the simplemap field display the address.

Default Latitude & Longitude only accepts whole numbers

In the fieldtype settings the Latitude/longitude options only allow whole numbers. This means the default setting is off a couple hundred kilometers from where I want it to be.

I need: 43.6525 and -79.381667 which is Toronto ON, but if I go with whole numbers I either end up in Niagara Falls (43, -79) or the middle of a farmers field in the middle of nowhere (44, -79).

Can the address be exported in components?

Looks like right now the plugin exports lat, lng, zoom and address, but address is a string. Is there a way to grab address, city, state & zip individually? If the address was broken into its component parts the plugin would be perfect for what I need.

Thanks.

Plugin is not detected

Hi,

thanks for this nice plugin.
I discovered one problem while deploying to my stage server.
The repository´s name is in CamelCase and was therefore not detected by Craft (2.6+).
Locally it worked fine on my mac but the server seems to be somewhat more strict regarding case sensitivity.
I forked your repo and simply renamed it to solve that.

Cheers,
Michael

Multilanguage - "not translatable"-checkbox ignored

I use this magnificent plugin in a multi-language environment.
When creating a simplemap-field I checked the "not translatable" box, because I need the plugin only to display a marker in the frontend - which is the same in every language.

When I set the marker-position in one language, it gets saved correctly, but in all other languages the marker has still the default lng/lat-values.

I'm using the latest release (1.5.1).
Reading through the issue-section it seems that this is a bug, that was already fixed?

Geographical Location Changes After Search and Click

I am using the field type to select one of the Virgin Islands because the entire island needs to be displayed on the map. Once I select the geographical location from the dropdown, I see the pin appear on the map but the value in the text field changes to "Unnamed Road, British Virgin Islands". I didn't select a road so I don't know why this happens.

If I save the entry and return to the edit form later, I see the map is on a different island with the pin on that "unnamed road". Is the map widget in the control panel only limited to saving road locations?

Touch when dragging

Hi. Solid update with 1.5. Thanks! Minor issue, which I'm not sure if it's to do with the plugin or google api.

On mobile, if your swiping down the page and you swipe on the map, you get the "use two finger to move map" message, which is great, but the map still detects the touch and will move the marker to wherever you tapped when you started to swipe. Hope that makes sense!?

"parts" functionality doesn't return anything

It looks like in a recent update, the "parts" functionality quit working for me. I'm trying to return a list of cities, like so:

  • Boston, MA
  • New York, NY
  • Washington, DC

And my code looked like so.
<li>{{ entry.map.parts.locality }}, {{ entry.map.parts.administrative_area_level_1_short }}</li>
And it was working. But now it renders <li>, </li>

However if I use the full address <li>{{ entry.map.address }}</li>
then I get actual data back:
<li>1600 Pennsylvania Ave NW, Washington, DC 20500</li>

Not outputting address / latitude & longitude

When trying to add a address in the text field (that's provided) & saving it. The text field is still blank & looking at the console log its returning data-latitude="0.00000000" data-longitude="0.00000000". The only time a address displays in the text field is when I physically grab the pin (on the map) and drag it to a location. Then there are values in the data-latitude & data-longitude. But this is sorta a pain if I am trying to put in a specific location.

Not really sure where to go from here

I'm using the Simple Map version 1.2.3 & Craft 2.6.2796
screenshot-simplemap

How to display map in template

Hello! How do I display the google map in my template?? I want it to show exactly as is when I'm inputting the address in my entries.

In my template I have these:

{{ block.address }}
{{ block.address.lat }}{{ block.address.lng }}

But I don't know what to do with it to display the map in the front end... Please help!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.