Title: [Plugin: Geolocation] jQuery Fix
Last modified: August 19, 2016

---

# [Plugin: Geolocation] jQuery Fix

 *  [Tim Bowen](https://wordpress.org/support/users/creativeslice/)
 * (@creativeslice)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/plugin-geolocation-jquery-fix/)
 * Version 0.1.1 of Geolocation conflicts with other plugins using jQuery. To fix
   this we removed the “noConflict” lines and changed the $j to jQuery – noConflict
   is implicite if you just use jQuery instead of a $ variable. Key was not to search
   and replace because some variables in his PHP were called $json and got changed
   to $jQueryson. The script from lines 156 to 325 should be this:
 *     ```
       <script type="text/javascript">
       			jQuery(function() {
       				jQuery(document).ready(function() {
       				    var hasLocation = false;
       					var center = new google.maps.LatLng(0.0,0.0);
       					var postLatitude =  '<?php echo esc_js(get_post_meta($post_id, 'geo_latitude', true)); ?>';
       					var postLongitude =  '<?php echo esc_js(get_post_meta($post_id, 'geo_longitude', true)); ?>';
       					var public = '<?php echo get_post_meta($post_id, 'geo_public', true); ?>';
       					var on = '<?php echo get_post_meta($post_id, 'geo_enabled', true); ?>';
   
       					if(public == '0')
       						jQuery("#geolocation-public").attr('checked', false);
       					else
       						jQuery("#geolocation-public").attr('checked', true);
   
       					if(on == '0')
       						disableGeo();
       					else
       						enableGeo();
   
       					if((postLatitude != '') && (postLongitude != '')) {
       						center = new google.maps.LatLng(postLatitude, postLongitude);
       						hasLocation = true;
       						jQuery("#geolocation-latitude").val(center.lat());
       						jQuery("#geolocation-longitude").val(center.lng());
       						reverseGeocode(center);
       					}
   
       				 	var myOptions = {
       				      'zoom': <?php echo $zoom; ?>,
       				      'center': center,
       				      'mapTypeId': google.maps.MapTypeId.ROADMAP
       				    };
       				    var image = '<?php echo esc_js(esc_url(plugins_url('img/wp_pin.png', __FILE__ ))); ?>';
       				    var shadow = new google.maps.MarkerImage('<?php echo esc_js(esc_url(plugins_url('img/wp_pin_shadow.png', __FILE__ ))); ?>',
       						new google.maps.Size(39, 23),
       						new google.maps.Point(0, 0),
       						new google.maps.Point(12, 25));
   
       				    var map = new google.maps.Map(document.getElementById('geolocation-map'), myOptions);
       					var marker = new google.maps.Marker({
       						position: center,
       						map: map,
       						title:'Post Location'<?php if(get_option('geolocation_wp_pin')) { ?>,
       						icon: image,
       						shadow: shadow
       					<?php } ?>
       					});
   
       					if((!hasLocation) && (google.loader.ClientLocation)) {
       				      center = new google.maps.LatLng(google.loader.ClientLocation.latitude, google.loader.ClientLocation.longitude);
       				      reverseGeocode(center);
       				    }
       				    else if(!hasLocation) {
       				    	map.setZoom(1);
       				    }
   
       					google.maps.event.addListener(map, 'click', function(event) {
       						placeMarker(event.latLng);
       					});
   
       					var currentAddress;
       					var customAddress = false;
       					jQuery("#geolocation-address").click(function(){
       						currentAddress = jQuery(this).val();
       						if(currentAddress != '')
       							jQuery("#geolocation-address").val('');
       					});
   
       					jQuery("#geolocation-load").click(function(){
       						if(jQuery("#geolocation-address").val() != '') {
       							customAddress = true;
       							currentAddress = jQuery("#geolocation-address").val();
       							geocode(currentAddress);
       						}
       					});
   
       					jQuery("#geolocation-address").keyup(function(e) {
       						if(e.keyCode == 13)
       							jQuery("#geolocation-load").click();
       					});
   
       					jQuery("#geolocation-enabled").click(function(){
       						enableGeo();
       					});
   
       					jQuery("#geolocation-disabled").click(function(){
       						disableGeo();
       					});
   
       					function placeMarker(location) {
       						marker.setPosition(location);
       						map.setCenter(location);
       						if((location.lat() != '') && (location.lng() != '')) {
       							jQuery("#geolocation-latitude").val(location.lat());
       							jQuery("#geolocation-longitude").val(location.lng());
       						}
   
       						if(!customAddress)
       							reverseGeocode(location);
       					}
   
       					function geocode(address) {
       						var geocoder = new google.maps.Geocoder();
       					    if (geocoder) {
       							geocoder.geocode({"address": address}, function(results, status) {
       								if (status == google.maps.GeocoderStatus.OK) {
       									placeMarker(results[0].geometry.location);
       									if(!hasLocation) {
       								    	map.setZoom(16);
       								    	hasLocation = true;
       									}
       								}
       							});
       						}
       						jQuery("#geodata").html(latitude + ', ' + longitude);
       					}
   
       					function reverseGeocode(location) {
       						var geocoder = new google.maps.Geocoder();
       					    if (geocoder) {
       							geocoder.geocode({"latLng": location}, function(results, status) {
       							if (status == google.maps.GeocoderStatus.OK) {
       							  if(results[1]) {
       							  	var address = results[1].formatted_address;
       							  	if(address == "")
       							  		address = results[7].formatted_address;
       							  	else {
       									jQuery("#geolocation-address").val(address);
       									placeMarker(location);
       							  	}
       							  }
       							}
       							});
       						}
       					}
   
       					function enableGeo() {
       						jQuery("#geolocation-address").removeAttr('disabled');
       						jQuery("#geolocation-load").removeAttr('disabled');
       						jQuery("#geolocation-map").css('filter', '');
       						jQuery("#geolocation-map").css('opacity', '');
       						jQuery("#geolocation-map").css('-moz-opacity', '');
       						jQuery("#geolocation-public").removeAttr('disabled');
       						jQuery("#geolocation-map").removeAttr('readonly');
       						jQuery("#geolocation-disabled").removeAttr('checked');
       						jQuery("#geolocation-enabled").attr('checked', 'checked');
   
       						if(public == '1')
       							jQuery("#geolocation-public").attr('checked', 'checked');
       					}
   
       					function disableGeo() {
       						jQuery("#geolocation-address").attr('disabled', 'disabled');
       						jQuery("#geolocation-load").attr('disabled', 'disabled');
       						jQuery("#geolocation-map").css('filter', 'alpha(opacity=50)');
       						jQuery("#geolocation-map").css('opacity', '0.5');
       						jQuery("#geolocation-map").css('-moz-opacity', '0.5');
       						jQuery("#geolocation-map").attr('readonly', 'readonly');
       						jQuery("#geolocation-public").attr('disabled', 'disabled');
   
       						jQuery("#geolocation-enabled").removeAttr('checked');
       						jQuery("#geolocation-disabled").attr('checked', 'checked');
   
       						if(public == '1')
       							jQuery("#geolocation-public").attr('checked', 'checked');
       					}
       				});
       			});
       		</script>
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [ctoynbee](https://wordpress.org/support/users/ctoynbee/)
 * (@ctoynbee)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/plugin-geolocation-jquery-fix/#post-2034156)
 * Is there a patch for this?
 *  [ctoynbee](https://wordpress.org/support/users/ctoynbee/)
 * (@ctoynbee)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/plugin-geolocation-jquery-fix/#post-2034157)
 * I’m afraid this plugin isn’t working under my configuration.
    I’m using wordpress
   3.2 and it’s conflicting with some other plugins I’ve got installed.
 * In particular it breaks Microkids related posts plugin: [http://www.microkid.net/wordpress/related-posts/](http://www.microkid.net/wordpress/related-posts/)
 * I think it’s related to the Jquery conflict stuff above but the fix in the post
   above isn’t working.
 * Had anyone else had any problems?
 * Thanks,
 * Chris.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘[Plugin: Geolocation] jQuery Fix’ is closed to new replies.

 * ![](https://ps.w.org/geolocation/assets/icon-256x256.png?rev=2871062)
 * [Geolocation](https://wordpress.org/plugins/geolocation/)
 * [Support Threads](https://wordpress.org/support/plugin/geolocation/)
 * [Active Topics](https://wordpress.org/support/plugin/geolocation/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/geolocation/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/geolocation/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [ctoynbee](https://wordpress.org/support/users/ctoynbee/)
 * Last activity: [14 years, 10 months ago](https://wordpress.org/support/topic/plugin-geolocation-jquery-fix/#post-2034157)
 * Status: not resolved