Alter Geolocator to remove or abbreviate province (British Columbia to BC as example)
I would like to abbreviate teh province output from "British Columbia" to "BC" in order to reduce the width of my postings as the full out put makes the posting box unneedingly larger vertically and thus more space used. I think that the answer lies in this code but not sure so... am being careful
<?php
/**
* JobRoller Geoloaction functions
* This file controls code for the Geolocation features.
* Geolocation adapted from 'GeoLocation' plugin by Chris Boyd -
http://geo.chrisboyd.net
*
*
* @version 1.1
* @author AppThemes
* @package JobRoller
* @copyright 2010 all rights reserved
*
*/
define('JR_DEFAULT_ZOOM', 1);
function jr_clean_coordinate($coordinate) {
$pattern = '/^(\-)?(\d{1,3})\.(\d{1,15})/';
preg_match($pattern, $coordinate, $matches);
if (isset($matches[0])) return $matches[0];
}
function jr_reverse_geocode($latitude, $longitude) {
$jr_gmaps_lang = get_option('jr_gmaps_lang');
$jr_gmaps_region = get_option('jr_gmaps_region');
$url = "http://maps.google.com/maps/api/geocode/json?latlng=".$latitude.",".$longitude."&language= ".$jr_gmaps_lang."®ion=".$jr_gmaps_region."&sen sor=false";
$result = wp_remote_get($url);
$json = json_decode($result['body']);
$city = '';
$country = '';
$short_country = '';
$state = '';
foreach ($json->results as $result)
{
foreach($result->address_components as $addressPart) {
if((in_array('locality', $addressPart->types)) && (in_array('political', $addressPart->types)))
$city = $addressPart->long_name;
else if((in_array('administrative_area_level_1', $addressPart->types)) && (in_array('political', $addressPart->types)))
$state = $addressPart->long_name;
else if((in_array('country', $addressPart->types)) && (in_array('political', $addressPart->types))) {
$country = $addressPart->long_name;
$short_country = $addressPart->short_name;
}
}
}
if(($city != '') && ($state != '') && ($country != ''))
$address = $city.', '.$state.', '.$country;
else if(($city != '') && ($state != ''))
$address = $city.', '.$state;
else if(($state != '') && ($country != ''))
$address = $state.', '.$country;
else if($country != '')
$address = $country;
if ($country=='United Kingdom') $short_country = 'UK';
if(($city != '') && ($state != '') && ($country != '')) {
$short_address = $city;
$short_address_country = $state.', '.$country;
} else if(($city != '') && ($state != '')) {
$short_address = $city;
$short_address_country = $state;
} else if(($state != '') && ($country != '')) {
$short_address = $state;
$short_address_country = $country;
} else if($country != '') {
$short_address = $country;
$short_address_country = '';
}
return array(
'address' => $address,
'country' => $country,
'short_address' => $short_address,
'short_address_country' => $short_address_country
);
}
function jr_geolocation_scripts() {
$zoom = JR_DEFAULT_ZOOM;
?>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/
js?sensor=true&language=<?php echo get_option('jr_gmaps_lang') ?>&region=<?php echo get_option('jr_gmaps_region') ?>"></script>
<script type="text/javascript">
var $j = jQuery.noConflict();
$j(function() {
$j(document).ready(function() {
var hasLocation = false;
var center = new google.maps.LatLng(0.0,0.0);
var postLatitude = '<?php global $posted, $job_details, $post; if (isset($posted['jr_geo_latitude'])) echo $posted['jr_geo_latitude']; elseif (isset($job_details->ID)) echo get_post_meta($job_details->ID, '_jr_geo_latitude', true); elseif (isset($post->ID)) echo get_post_meta($post->ID, '_jr_geo_latitude', true); ?>';
var postLongitude = '<?php global $posted, $job_details; if (isset($posted['jr_geo_longitude'])) echo $posted['jr_geo_longitude']; elseif (isset($job_details->ID)) echo get_post_meta($job_details->ID, '_jr_geo_longitude', true); elseif (isset($post->ID)) echo get_post_meta($post->ID, '_jr_geo_longitude', true); ?>';
if((postLatitude != '') && (postLongitude != '') ) {
center = new google.maps.LatLng(postLatitude, postLongitude);
hasLocation = true;
$j("#geolocation-latitude").val(center.lat());
$j("#geolocation-longitude").val(center.lng());
reverseGeocode(center);
}
var myOptions = {
'zoom': <?php echo $zoom; ?>,
'center': center,
'mapTypeId': google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('geolocati on-map'), myOptions);
var marker = '';
/*if((!hasLocation) && (google.loader.ClientLocation)) {
center = new google.maps.LatLng(google.loader.ClientLocation.la titude, google.loader.ClientLocation.longitude);
reverseGeocode(center);
}
else */if(!hasLocation) {
map.setZoom(1);
}
google.maps.event.addListener(map, 'click', function(event) {
reverseGeocode(event.latLng);
});
var currentAddress;
var customAddress = false;
/*$j("#geolocation-address").click(function(){
currentAddress = $j(this).val();
if(currentAddress != '')
$j("#geolocation-address").val('');
});*/
$j("#geolocation-load").click(function(){
if($j("#geolocation-address").val() != '') {
customAddress = true;
currentAddress = $j("#geolocation-address").val();
geocode(currentAddress);
return false;
} else {
marker.setMap(null);
marker = '';
$j("#geolocation-latitude").val('');
$j("#geolocation-longitude").val('');
return false;
}
});
$j("#geolocation-address").keyup(function(e) {
if(e.keyCode == 13)
$j("#geolocation-load").click();
});
function placeMarker(location) {
if (marker=='') {
marker = new google.maps.Marker({
position: center,
map: map,
title:'Job Location'
});
}
marker.setPosition(location);
map.setCenter(location);
if((location.lat() != '') && (location.lng() != '')) {
$j("#geolocation-latitude").val(location.lat());
$j("#geolocation-longitude").val(location.lng());
}
/*if(!customAddress || $j("#geolocation-address").val() == '') {
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);
reverseGeocode(results[0].geometry.location);
if(!hasLocation) {
map.setZoom(9);
hasLocation = true;
}
}
});
}
$j("#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) {
var address, city, country, state;
for ( var i in results ) {
var address_components = results[i]['address_components'];
for ( var j in address_components ) {
var types = address_components[j]['types'];
var long_name = address_components[j]['long_name'];
var short_name = address_components[j]['short_name'];
if ( $j.inArray('locality', types)>=0 && $j.inArray('political', types)>=0 ) {
city = long_name;
}
else if ( $j.inArray('administrative_area_level_1', types)>=0 && $j.inArray('political', types)>=0 ) {
state = long_name;
}
else if ( $j.inArray('country', types)>=0 && $j.inArray('political', types)>=0 ) {
country = long_name;
}
}
}
if((city) && (state) && (country))
address = city + ', ' + state + ', ' + country;
else if((city) && (state))
address = city + ', ' + state;
else if((state) && (country))
address = state + ', ' + country;
else if(country)
address = country;
$j("#geolocation-address").val(address);
placeMarker(location);
return true;
/*if(results[1]) {
var address = results[1].formatted_address;
if(address == "")
address = results[7].formatted_address;
else {
$j("#geolocation-address").val(address);
placeMarker(location);
}
}*/
}
});
}
return false;
}
// Prevent form submission on enter key
$j("#submit_form").submit(function(e) {
if ($j("input:focus").attr("id")=='geolocation-address') return false;
});
});
});
</script>
<?php
}