Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Commit

Permalink
update to latest code
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Farr committed Nov 23, 2019
1 parent 28c9e1b commit df9183a
Show file tree
Hide file tree
Showing 11 changed files with 446 additions and 166 deletions.
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8

# 2 space indentation
indent_style = space
indent_size = 2

[**.md]
# trailing spaces have a meaning in markdown
trim_trailing_whitespace = false
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Please note: This project is not maintained anymore!
Feel free to discuss issues here but please do not expect new features or changes in the default behavior.
27 changes: 20 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
# $.geocomplete() - Version 1.5
# $.geocomplete() - Version 1.7.0
## jQuery Geocoding and Places Autocomplete Plugin

An advanced jQuery plugin that wraps the Google Maps API's [Geocoding](https://code.google.com/apis/maps/documentation/javascript/geocoding.html) and [Places Autocomplete](https://code.google.com/apis/maps/documentation/javascript/places.html#places_autocomplete) services. You simply provide an input that lets you search for locations with a nice autocomplete dropdown. Optionally add a container to show an interactive map and a form that will be populated with the address details.

View the [annotated source](http://ubilabs.github.com/geocomplete/docs/).

## ⚠️ NOT MAINTAINED

_Please note:_ **This project is not maintained anymore. We do not use jQuery in production and switched to React about two years ago. Feel free to discuss issues here but please do not expect new features or changes in the default behavior.**

For a new and way more flexible solution, see our [React Geosuggest](http://ubilabs.github.io/react-geosuggest/) plugin.

If you would like to take over the project, please let us know! There are many people out there who would be happy to have new supporters.

## Basic Usage

To convert an input into an autocomplete field, simply call the Geocomplete plugin:
Expand All @@ -25,13 +33,14 @@ Here is a list of basic uses:
* [Attribute](http://ubilabs.github.com/geocomplete/examples/custom_attribute.html) - Using custom attributes to populate data.
* [Multiple results](http://ubilabs.github.com/geocomplete/examples/multiple_results.html) - Handling multiple results from the geocoder.
* [Draggable](http://ubilabs.github.com/geocomplete/examples/draggable.html) - A draggable marker to redefine the position.
* [Styled](http://ubilabs.github.com/geocomplete/examples/styled.html) - A styled map example.

## Requirements

Make sure you include the Google Maps API with the Places Library before loading this plugin as described [here](https://developers.google.com/maps/documentation/javascript/places#loading_the_library).

````html
<script src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script>
```html
<script src="http://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places"></script>
<script src="jquery.geocomplete.js"></script>
```

Expand All @@ -41,7 +50,7 @@ If you use the plugin without showing a map you must display the "[powered by Go

To trigger a geocoding request from outside (eg. when hitting the "find" button), simply trigger the "geocode" event on the element.

````javascript
```javascript
$("input").geocomplete();

// Trigger geocoding request.
Expand Down Expand Up @@ -70,6 +79,8 @@ By default the plugin analyses the `name` attribute of the containers child node

If the element is an input, the value will be replaced otherwise the plugin overrides the current text.

If you have multiple geocomplete fields on a page, use `detailsScope` option scope your 'details' container.

**Note**: Some address components such as "country" return an additional `short_name`. You can access them by simply adding `_short` at the end of the type.

Simple Example:
Expand Down Expand Up @@ -125,6 +136,7 @@ $("#my_input").geocomplete({

* `map` - Might be a selector, a jQuery object or a DOM element. Default is `false` which shows no map.
* `details` - The container that should be populated with data. Defaults to `false` which ignores the setting.
* 'detailsScope' - Allows you to scope the 'details' container and have multiple geocomplete fields on one page. Must be a parent of the input. Default is 'null'
* `location` - Location to initialize the map on. Might be an address `string` or an `array` with [latitude, longitude] or a `google.maps.LatLng`object. Default is `false` which shows a blank map.
* `bounds` - Whether to snap geocode search to map bounds. Default: `true` if false search globally. Alternatively pass a custom LatLngBounds object
* `detailsAttribute` - The attribute's name to use as an indicator. Default: `"name"`
Expand All @@ -144,7 +156,7 @@ $("#my_input").geocomplete({

You can subscribe to events of the geocode plugin by using the default jQuery syntax:

````javascript
```javascript
$("input")
.geocomplete()
.bind("geocode:result", function(event, result){
Expand All @@ -159,14 +171,16 @@ The following events are supported:
* `"geocode:multiple"` - Fired immediately after the "result" event if multiple results were found. Passes an array of all results.
* `"geocode:dragged"` - Fired when the marker's position was modified manually. Passes the updated location.
* `"geocode:click"` - Fired when 'click' event occurs on the map. Passes the location where the click had place.
* `"geocode:mapdragged"` - Fired when the map bounds are modified by dragging manually. Passes the location of the current map center.
* `"geocode:idle"` - Fired when the map becomes idle after panning or zooming. Passes the location of the current map center.

## Methods and Properties

You can access all properties and methods of the plugin from outside. Simply add a string as the first argument to the `.geocomplete` method after you initialized the plugin.

Example:

````javascript
```javascript
// Initialize the plugin.
$("input").geocomplete({ map: ".map_canvas" });

Expand Down Expand Up @@ -197,4 +211,3 @@ More information can be found here: https://developers.google.com/maps/documenta
## About

Developed by [Martin Kleppe](http://twitter.com/aemkei) at [Ubilabs](http://ubilabs.net).

29 changes: 29 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "geocomplete",
"version": "1.7.0",
"homepage": "http://ubilabs.github.com/geocomplete/",
"authors": [
"Martin Kleppe <[email protected]>"
],
"description": "jQuery Geocoding and Places Autocomplete Plugin",
"main": "jquery.geocomplete.js",
"keywords": [
"geocoding",
"map",
"places",
"api",
"search",
"google"
],
"license": "MIT",
"dependencies": {
"jquery": ">= 1.9.0"
},
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
]
}
34 changes: 32 additions & 2 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
# Changelog - $.geocomplete()
Version 1.7

* Merged pull requests

Version 1.6

* Cycle through subtypes in address components.
* Add "place_id" to places details.
* Avoid exception if getPlace() returns undefined

Version 1.5

* Added autoselect option.
* Add zoom_changed event support.
* Fixed blur autocomplete.
* Keep result at text input after focusout.
* Add blur boolean option.
* Add marker to map on initialize.
* Add geocode:click event on the map.

Version 1.4

* Use lat/lng location option to set initial map
* Return element after calling methods via API.
* Add option markerOptions.disabled.
* Add support for Places API componentRestrictions option

Version 1.3

* Add "name" to places details.
* Add reference field from Places Details call.

Version 1.2

Expand All @@ -7,7 +37,7 @@ Version 1.2

Version 1.1

* Add API to access methods and properties from outside
* Add API to access methods and properties from outside
* Add events for draggable marker

Version 1.0
Expand Down
3 changes: 3 additions & 0 deletions examples/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ <h3>Address-Details</h3>
<label>State</label>
<input name="administrative_area_level_1" type="text" value="">

<label>Place ID</label>
<input name="place_id" type="text" value="">

<label>ID</label>
<input name="id" type="text" value="">

Expand Down
77 changes: 77 additions & 0 deletions examples/multiple_fields.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<!DOCTYPE html>
<html>
<head>
<title>$.geocomplete()</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="styles.css" />
<style type="text/css" media="screen">
form { width: 300px; float: left; }
fieldset { width: 320px; margin-top: 20px}
fieldset label { display: block; margin: 0.5em 0 0em; }
fieldset input { width: 95%; }
.location { margin-top: 20px; }
</style>
</head>
<body>

<form>

<div class="location">
<input class="geocomplete" type="text" placeholder="Type in an address" value="Empire State Bldg" />
<input class="find" type="button" value="find" />

<fieldset class="details">
<h3>Address-Details</h3>


<label>Latitude</label>
<input name="lat" type="text" value="">

<label>Longitude</label>
<input name="lng" type="text" value="">


</fieldset>
</div>

<div class="location">
<input class="geocomplete" type="text" placeholder="Type in an address" value="Eiffel Tower" />
<input class="find" type="button" value="find" />

<fieldset class="details">
<h3>Address-Details</h3>

<label>Latitude</label>
<input name="lat" type="text" value="">

<label>Longitude</label>
<input name="lng" type="text" value="">


</fieldset>
</div>

</form>

<script src="http://maps.googleapis.com/maps/api/js?sensor=false&amp;libraries=places"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

<script src="../jquery.geocomplete.js"></script>

<script>
$(function(){
$(".geocomplete").geocomplete({
details: ".details",
detailsScope: '.location',
types: ["geocode", "establishment"],
});

$(".find").click(function(){
$(this).parents(".location").find(".geocomplete").trigger("geocode");
});
});
</script>

</body>
</html>

42 changes: 42 additions & 0 deletions examples/styled.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html>
<head>
<title>GeoComplete</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>

<form>
<input id="geocomplete" type="text" placeholder="Type in an address" size="90" />
</form>

<div class="map_canvas"></div>

<script src="http://maps.googleapis.com/maps/api/js?sensor=false&amp;libraries=places"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

<script src="../jquery.geocomplete.js"></script>
<script src="logger.js"></script>

<script>
$(function(){

// Sample style taken from https://snazzymaps.com/style/70/unsaturated-browns
var mapStyles = [{"elementType":"geometry","stylers":[{"hue":"#ff4400"},{"saturation":-68},{"lightness":-4},{"gamma":0.72}]},{"featureType":"road","elementType":"labels.icon"},{"featureType":"landscape.man_made","elementType":"geometry","stylers":[{"hue":"#0077ff"},{"gamma":3.1}]},{"featureType":"water","stylers":[{"hue":"#00ccff"},{"gamma":0.44},{"saturation":-33}]},{"featureType":"poi.park","stylers":[{"hue":"#44ff00"},{"saturation":-23}]},{"featureType":"water","elementType":"labels.text.fill","stylers":[{"hue":"#007fff"},{"gamma":0.77},{"saturation":65},{"lightness":99}]},{"featureType":"water","elementType":"labels.text.stroke","stylers":[{"gamma":0.11},{"weight":5.6},{"saturation":99},{"hue":"#0091ff"},{"lightness":-86}]},{"featureType":"transit.line","elementType":"geometry","stylers":[{"lightness":-48},{"hue":"#ff5e00"},{"gamma":1.2},{"saturation":-23}]},{"featureType":"transit","elementType":"labels.text.stroke","stylers":[{"saturation":-64},{"hue":"#ff9100"},{"lightness":16},{"gamma":0.47},{"weight":2.7}]}];

var options = {
map: ".map_canvas",
location: "Dublin",
mapOptions: {
styles: mapStyles
}
};

$("#geocomplete").geocomplete(options);

});
</script>
</body>
</html>

Loading

0 comments on commit df9183a

Please sign in to comment.