Code Monkey home page Code Monkey logo

jquery-locationpicker-plugin's Introduction

JQuery Location Picker plugin

Location Picker

This plug-in allows finding and selecting a location on the Google map. Along with single point selection, it allows area selection by choosing a point and specifying a radius. The selection can be saved to any HTML input element or processed by Javascript with callback support.

An optional automatic address resolver can reverse geocode the selection to an address. The plug-in also supports searching by address typed into the bound input element which uses auto-complete feature from Google API to make the search process easier. In this case the marker will be automatically positioned on the map after successful address resolution.

Usage

The plug-in requires jQuery and the Google Maps API. Integration is pretty simple:

  • Add jQuery and Google Maps API to the <head> of your HTML file:
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
// be careful to include the parameter "libraries=places"
<script type="text/javascript" src='http://maps.google.com/maps/api/js?sensor=false&libraries=places'></script>
<script src="js/locationpicker.jquery.js"></script>
  • Put container somewhere in your page's <body>:
<div id="somecomponent" style="width: 500px; height: 400px;"></div>
  • Attach the plug-in to container:
<script>
$('#somecomponent').locationpicker();
</script>

Documentation and Examples

Documentation along with examples available here.

Credits

jquery-locationpicker-plugin's People

Contributors

brendannee avatar corvis avatar davidphilip avatar emanuelecoppola avatar hasanove avatar jasonhinkle avatar ksg91 avatar sumragen avatar sykamraju 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jquery-locationpicker-plugin's Issues

Can you give a sample html page that goes with this?

Hi, I have the json and the js, but I can't figure out how you call the event. I am new to this. I have 'viewed source' and tried to copy your entire demo page, but mine doesn't work. Can you give a one page example with html? Thanks very much,
Charlotte

Maps show up only on the upper left corner when shown after hidden

First, thanks a lot for the great plugin, this was my 'EXACT' requirement and coudnt believe someone had a plugin to do just that. Being a non-programmer by profession, this was a life saver!

  1. My page has a structure something like this:
<div class="geo">
<div id="maps" style="width: 100%; height: 400px;"></div>
</div>
  1. On document ready I have a function that hides the parent div

    $(document).on("pagecreate","#CommSchedulingPage",function(){
      $(".geo").hide();
  2. I have button, when click on it, I show the parent div

    $(".geo").show();
  3. On show , the maps only occupy the upper left portion of the #maps div as shown in attached image.

I initialize location picker as below at the end body section:, should I add anything else? Need help.

$(function(){
$('#maps').locationpicker({
location: {latitude: 13.204492, longitude: 77.707691},    
radius: 500,
inputBinding: {
    latitudeInput: $('#lat'+'1'),
    longitudeInput: $('#long'+'1'),
    radiusInput: $('#radius'+'1'),
    locationNameInput: $('#address'+'1')
},
enableAutocomplete: true,
onchanged: function(currentLocation, radius, isMarkerDropped) {
//alert("Location changed. New location (" + currentLocation.latitude + ", " + currentLocation.longitude + ")");
$('#lat'+'1').val(currentLocation.latitude);
$('#long'+'1').val(currentLocation.longitude);
$('#radius'+'1').val(radius);


}
});
});

Actual page in action: http://www.yfs.co.in/webui/CommScheduling.html

Click yes for 'Notify users at certain locations only?'
and then click yes for 'Want to add additional locations to notify?'

mapsproblem

Allow passing options to the google map

It would be great if you could pass options to the google map, as specified by Google Maps API V3. Maybe something like

var gmapDefaults = {
            zoom: settings.zoom,
            center: new google.maps.LatLng(settings.location.latitude, settings.location.longitude),
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            mapTypeControl: false,
            disableDoubleClickZoom: false,
            scrollwheel: settings.scrollwheel,
            streetViewControl: false,
            radius: settings.radius,
            locationName: settings.locationName,
            settings: settings,
            draggable: settings.draggable
};

var gmapContext = new GMapContext(this, $.extend({}, gMapDefaults, gMapOptions);

Inconsistent Radius Parameter Units

When the map marker is moved, or the location picker is zoomed, it converts the input units from miles in to metres (understandable because this is the units the Gmaps API uses). However - It appears to always want the initial inputs in terms of miles.

This can cause problems when using it in conjunction with other libraries (such as bootstrap-slider) as the two libraries set the .val() of the at different times. Here is an example screenshot where the console output shows the problem:

conflict with bootstrap-slider

One solution to this problem would be just to have the slider be in metres as well. Is there a way to tell location-picker NOT to convert the input in the radius box from miles to metres, and just to keep everything in metres?

Thanks :)

Enter-key submits form when selecting a location

To prevent this put the following code at line 140:

            // Prevent form from being submitted if user hit enter.
            inputBinding.locationNameInput.keypress(function(event){
                if (event.keyCode === 13){ return false; }
            });

Working with hidden DIVs

This is not an issue, is more like a question

How can some one work with the map when its loaded to a hidden DIV then made apear via JQUERY?

Working with bootstrap modal

Hi,
I want to show locationpicker in bootstrap modal. But I am unable to show map in modal.
Can you guide me how I can do that.

Thanks

Any other address component example to get correct street component?

in my case i got this address when dragging marker to other coordinate

Jalan Jakarta No.21, Batununggal, Kota Bandung, Jawa Barat 40271, Indonesia

my code

$('#location_picker').locationpicker({
    location: {latitude: -6.8959712, longitude: 107.6309693},
    locationName: "",
    radius: null,
    zoom: 15,
    scrollwheel: true,
    inputBinding: {
        latitudeInput: $('#latitude'),
        longitudeInput: $('#longitude'),
        radiusInput: null,
        locationNameInput: $('#address')
    },
    enableAutocomplete: false,
    enableReverseGeocode: true,
});

if i use this code as in example

function updateControls(addressComponents) {
    $('#address').val(addressComponents.addressLine1);
    $('#city').val(addressComponents.city);
    $('#province').val(addressComponents.stateOrProvince);
    $('#zipcode').val(addressComponents.postalCode);
    $('#country_id').val(addressComponents.country);
}

$('#location_picker').locationpicker({
    location: {latitude: -6.8959712, longitude: 107.6309693},
    radius: null,
    zoom: 15,
    enableAutocomplete: true,
    enableReverseGeocode: true,
    onchanged: function (currentLocation, radius, isMarkerDropped) {
        var addressComponents = $(this).locationpicker('map').location.addressComponents;
        updateControls(addressComponents);
    },
    oninitialized: function(component) {
        var addressComponents = $(component).locationpicker('map').location.addressComponents;
        updateControls(addressComponents);
    }
});

I got "21 Jl. Jakarta" for street component,
In my country the correct format for street address is "Jalan Jakarta No.21"

how can i get correct street address format?

thank you

Change coordinates on the map with change event on the coordinates inputs

How can I reinitialize the map by using new coordinates that are added automatically?

I am using the map in a modal but the coordinates are out of the modal.

I am updating the coordinates automatically, and I tried to trigger change event on them but the coordinates from map dont update like this, I have to manually add something to the field in order to update. I dont know why the change event doesn't work on the coordinates input.

Problem with Umlaute (German)

The picker has problems with Umlaute (like ü) in the city name (and very likely in other fields, too). E.g. the city name München is truncated to M.

Leftover Autocomplete .pac-container elements

In my project I initialize and remove multiple locationpickers in the same window, and there are multiple new .pac-container and pac-container stying elements appended to the head of the doc. Can these be removed? Or a way to $(".picker").data("locationpicker").remove()

Can you give a sample html page that goes with this?

Hi, I have the json and the js, but I can't figure out how you call the event. I am new to this. I have 'viewed source' and tried to copy your entire demo page, but mine doesn't work. Can you give a one page example with html? Thanks very much,
Charlotte

How to add HTML5 Geolocation?

How to add HTML5 Geolocation?

How do i add the HTML5 Geolocation in order to initialise the start location to the user location?

How to fetch district?

In regards to #24 you released v0.1.11, which replaces the district by the proper city name. But the district information is also relevant in many cases. So wouldn't it be better to return both? See this as a feature request :-)

Async loading google maps

When loading google maps api asynchronously, the plugin fails to load autocomplete.

This is the error I get:

TypeError: Cannot read property 'Autocomplete' of undefined
#11 http://127.0.0.1/eqfw/js/jquery.locationpicker.js:13:69
#10 http://127.0.0.1/eqfw/js/jquery.locationpicker.js:13:124 setupInputListenersInput()
#9 http://127.0.0.1/eqfw/js/jquery.locationpicker.js:24:1205 HTMLDivElement.()
#8 http://127.0.0.1/eqfw/js/jquery-2.1.3.min.js:2:2882 Function.n.extend.each()
#7 http://127.0.0.1/eqfw/js/jquery-2.1.3.min.js:2:847 n.fn.n.each()
#6 http://127.0.0.1/eqfw/js/jquery.locationpicker.js:24:13 $.fn.locationpicker()
#5 http://127.0.0.1/eqfw/js/eqs.funciones.js:1008:10 HTMLDocument.()
#4 http://127.0.0.1/eqfw/js/jquery-2.1.3.min.js:2:26911 j()
#3 http://127.0.0.1/eqfw/js/jquery-2.1.3.min.js:2:27220 Object.k.add as done
#2 http://127.0.0.1/eqfw/js/jquery-2.1.3.min.js:2:29326 n.fn.ready()
#1 http://127.0.0.1/eqfw/js/jquery-2.1.3.min.js:2:24411 n.fn.init()

This is how I load google maps api and my custom callback function:

function initialize(obj,varlat,varlon,varzoom,varradius,varautocomplete){
if (varzoom==undefined) varzoom=15;
if (varradius==undefined) varradius=30;
if (varautocomplete==undefined) varautocomplete=true;
if (varlat==undefined || varlon==undefined) {
varzoom=5;
varlat=10.65;
varlon=-71.633333;
}
$(function(){
$(obj).locationpicker({
location:{latitude:varlat,longitude:varlon},
radius:varradius,
zoom:varzoom,
enableAutocomplete:varautocomplete,
inputBinding:{
latitudeInput:$('#lat'),
longitudeInput:$('#lon'),
locationNameInput:$('#dummyaddr')
}
});
if (varzoom==5){
if ("geolocation" in navigator){
navigator.geolocation.getCurrentPosition(function(position){
$(obj).locationpicker('location',{latitude:position.coords.latitude,longitude:position.coords.longitude});
});
}
}
});
}
function loadScript() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp' +
'&signed_in=true&callback=initialize';
document.body.appendChild(script);
}
window.onload = loadScript;

Programatically Set the Location Picker

Love the plugin, I'm having an issue attempting to programmatically set the map location.

This questions has been asked a few times without an answer:
http://stackoverflow.com/questions/31631777/logicify-location-picker-using-dynamic-change-for-input
#20

Essentially I would assume that I could programmatically set the values of latitude and/or longitude and the plugin would respond as if I had typed those values in (through the inputBinding latitude and longitude 'on('change' functions). However it doesn't.

I've tried various attempts at calling .locationpicker() after resetting the values or .trigger() on the values themselves. I'm not sure how to proceed if I can't get the inputBindings to fire.

Can anyone steer me in a direction to get the inputBinding functions to pick up on programmatically setting the lat and long?

Need marker to be fixed, only map should be movable

I do not want marker to be draggable, it should be fixed to the center of div, I want only the map to be draggable.

So that user can just drag the map and set the location by its fixed marker.

Note: Now the user has to search the marker, if lost while playing around the map. A fixed marker will help a lot.

Autocomplete and clearfix problem

Hy ^^

First of all, thank you for this amazing work ! It's simple to use and I think all pluigin must be as simple as that ^^

I have a problem with Autocomplete. When I use a clearfix (any of them) in any parent, the autocomplete doesn't work anymore. I don't know if it's already knew but you have any solutions it will be nice ^^

Thanks in advance and sorry for my english !

EDIT: Ok sorry z-index just worked fine for me ^^

how to show map type control ?

I trace this code, default mapTypeControl is false. is it possible let us enable it ?

var gmapContext = new GMapContext(this, {
                zoom: settings.zoom,
                center: new google.maps.LatLng(settings.location.latitude, settings.location.longitude),
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                mapTypeControl: false,
....

Order of Onchanged & updateInputValues inconsistent

The order in which the library calls updateInputValues and the user-specified onchanged handler is inconsistent. When using autocomplete it is in the following order:
updateInputValues(inputBinding, context);
context.settings.onchanged.apply(gmapContext.domContainer, ...

This allows for the onchanged function to overwrite the value automatically set in the locationName field by updateInputValues (which is useful if you don't want the default formatted address string that updateInputValues inserts).

However in the event handler for dragend, it is done the other way
updateInputValues(gmapContext.settings.inputBinding, gmapContext);
context.settings.onchanged.apply(gmapContext.domContainer, ...

which nullifies any changes the user makes to the locationName input in the onchanged handler.

Patch:

From 0198c6b2fdb9c838a33812030a4e0dfa3041eb7e Mon Sep 17 00:00:00 2001
From: wspencer <[email protected]>
Date: Thu, 23 Jun 2016 09:31:44 -0600
Subject: [PATCH 1/1] locationpicker: Standardizes the order of the onchanged
 function call in relation to updateInputValues.

---
 src/locationpicker.jquery.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/locationpicker.jquery.js b/src/locationpicker.jquery.js
index 81a2c50..f1e3a95 100644
--- a/src/locationpicker.jquery.js
+++ b/src/locationpicker.jquery.js
@@ -372,8 +372,8 @@
             google.maps.event.addListener(gmapContext.marker, "dragend", function(event) {
                 GmUtility.setPosition(gmapContext, gmapContext.marker.position, function(context){
                     var currentLocation = GmUtility.locationFromLatLng(gmapContext.location);
-                    context.settings.onchanged.apply(gmapContext.domContainer, [currentLocation, context.radius, true]);
                     updateInputValues(gmapContext.settings.inputBinding, gmapContext);
+                    context.settings.onchanged.apply(gmapContext.domContainer, [currentLocation, context.radius, true]);
                 });
             });
             GmUtility.setPosition(gmapContext, new google.maps.LatLng(settings.location.latitude, settings.location.longitude), function(context){
--
1.9.1

Any way to grab the map zoom level?

hi all this is a superb plugin for easily grabbing lat and lon especially with the modal view.

I need to also grab the map zoom level. Any way I can do this?

Thanks in advance

Initialize locationNameInput empty

Is it possible to initialize the locationNameInput empty?

Otherwise would it be a good idea to clear the input value with oninitialize?

Geolocation option

The option to geolocate the user seems to be missing right now. There can be google's crosshair icon on the top of the map for geolocation, and also an option while initialization, if user should be geolocated by default.
Is the absence of this feature by design? If not, I can submit a PR shortly, as I've implemented it locally for my requirements.
Thanks

Select multiple locations

I want to select multiple locations in map and get latitude and longitude for each of the select location. How can I use this plug-in for the same?

Demo doesn't work (https issues)

When looking at the demo page, scripts do not get loaded because they are being loaded over HTTP, while the page itself is HTTPS.

Mixed Content: The page at 'https://logicify.github.io/jquery-locationpicker-plugin/' was loaded over HTTPS, but requested an insecure script 'http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js'. This request has been blocked; the content must be served over HTTPS.

This is an issue for people using HTTPS Everywhere which always goes for the https version of a page.

City property from addressComponents empty

The issue "How can I get proper city name? #24" happens again.

If you pick this location: "144-15 68th Rd, Flushing, NY 11367, EE. UU.". The addressComponents does not have the "city" property. It happens in other places of NY also.

Thanks

Bower out of date

Looks like bower is now out of date. Can you tag the current repo with a new version?

I maybe getting confused as the dist has been committed and is not up to date.

Get my current location

Is there a way to get my current location?
If yes, kindly explain it. Put it in your documentation as well.

Thank you,
Supun Silva

gmapContext.onlocationnotfound is not a function

TypeError: gmapContext.onlocationnotfound is not a function

gmapContext.onlocationnotfound();

Produce when you try some text search on autosuggestion, no record found and then you press enter.

Autocomplete cannot select city/suburb (i.e. broad area)

Hello,

As the title states, I have implemented functionality similar to the 'Subscribing for Events' example seen on this page (http://logicify.github.io/jquery-locationpicker-plugin/#usage).

When I select a city as a location, for example 'Sydney, New South Wales, Australia' it autocompletes to '343 George St, Sydney NSW 2000, Australia'.

However the example that Google supplies allows you to select a city as a location rather than a specific address. (https://developers.google.com/maps/documentation/javascript/examples/places-searchbox).

Is there something I'm missing to fix this issue?

    $(document).ready(function() {
        $('#map').locationpicker({
            location: {latitude: -27.4732212, longitude: 153.02787250000006},   
            radius: 1,
            inputBinding: {
                latitudeInput: $('#us2-lat'),
                longitudeInput: $('#us2-lon'),

                locationNameInput: $('#us2-address')
            },
                enableAutocomplete: true,
                onchanged: function (currentLocation, radius, isMarkerDropped) {
                    // Uncomment line below to show alert on each Location Changed event
                    //alert("Location changed. New location (" + currentLocation.latitude + ", " + currentLocation.longitude + ")");
                }
        });
    });

Any help would be greatly appreciated.

Autocomplete not working

Is there some sort of registration that needs to happen with Google? Great plugin btw. Thanks a bunch.

How can I get proper city name?

In your example Advanced usage of geo decoder features, when I place the marker on a random big city, the city name is either empty or shows the name of the district.

E.g. if I place the marker somewhere in Paris, the address would be

43-51 Boulevard Saint-Jacques, 75014 Paris, Frankreich

But instead, city remains empty

  • Street: 43-51 Boulevard Saint-Jacques
  • Postal code: 75014
  • City: [empty]
  • State: IDF
  • Country: FR

Unfortunately, the addressComponents

 var addressComponents = $(this).locationpicker('map').location.addressComponents;

doesn't contain the correct city name (Paris). Examples in Berlin outputted the district name instead of the city.

How can I access the proper city name?

Autocomplete not working

I am loading the google api with the key:

<script type="text/javascript" src='https://maps.googleapis.com/maps/api/js?key=MYKEY0&libraries=places'></script>

But the autocomplete isnt working anymore, any suggestion (and yes, the enableAutocomplete: true is enabled)

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.