Jump to content

Specify a latitude and longitude in Google Maps plugin


foodribber

Recommended Posts

I have downloaded Post-Google-Maps plugin and it works great. But I would like to change the default latitude and longitude and can't figure out how. I have posted this question on their support site, but I haven't received an answer, and the site doesn't seem to be actively monitored. I'm hoping there is an easy solution, and that someone on this board can help me.

 

The plugin contains two php pages.

 

Here is the code from post-google-map.php.

 

<?php
/*
Plugin Name: Post Google Map
Plugin URI: http://webdevstudios.com/support/wordpress-plugins/
Description: Plugin allows posts to be linked to specific addresses and coordinates and display plotted on a Google Map.  Use shortcode [google-map] to display map directly in your post/page.  Map shows plots for each post with filter options and preview when hovered. <a href="options-general.php?page=post-google-map/post-google-map.php">Plugin Settings</a> |
Version: 1.5.1
Author: WebDevStudios.com
Author URI: http://webdevstudios.com
*/

$gmp_version = "1.5.1";
//hook for adding admin menus
add_action('admin_menu', 'gmp_menu');

//hook for adding a new address
add_action('admin_menu', 'gmp_add_new_address');

//hook for post/page custom meta box
add_action('admin_menu', 'gmp_meta_box_add');

//hook for add a map to the content
add_filter('the_content', 'gmp_widget');

//hook for loading widget
add_action('plugins_loaded', 'gmp_widget_init');

//save/update post/page address fields from meta box
function gmp_add_new_address() {
$gmp_submit = $_POST["gmp_submit"];
If (isset($gmp_submit) && !empty($gmp_submit) ) {
	post_meta_tags();
}
}

//add_action('edit_post', 'post_meta_tags');
//add_action('publish_post', 'post_meta_tags');
//add_action('save_post', 'post_meta_tags');
//add_action('edit_page_form', 'post_meta_tags');

function getWords($text, $limit)
{
$array = explode(" ", strip_tags($text), $limit+1);

if (count($array) > $limit)
{
	unset($array[$limit]);
}

return implode(" ", $array);
}

function gmp_widget_options() {
//widget options form
if ($_POST['gmp_form_submit']) {
	update_option('gmp_widget_title', esc_attr($_POST['gmp_widget_title']) );
}
//load widget title
$gmp_widget_title = get_option('gmp_widget_title');
?>
<div>
         <label for="cc_form_title">
          <strong><?php _e('Title:'); ?></strong>
        </label>
        <input style="width: 100%; margin-bottom:1em;" id="gmp_widget_title" name="gmp_widget_title" type="text" value="<?php echo htmlspecialchars(stripslashes($gmp_widget_title)); ?>" />
        Setting a title will override category tabs from displaying
        <input type="hidden" name="gmp_form_submit" value="Submit" />
    </div>
<?php
}

function gmp_widget_init() {
//widget code
	if ( !function_exists('register_sidebar_widget') )
		return;
	function gmp_widget_init2() {
		gmp_widget('xxx');
	}
	function gmp_widget($content) {
		global $wpdb;
		global $post;

		$options_arr = get_option('gmp_params');

		$key = $options_arr["post_gmp_params"];
		$imgpath = WP_PLUGIN_URL . '/post-google-map/markers/';

		$gmp_map_type = $options_arr["post_gmp_map_type"];
		$gmp_cats = $options_arr["post_gmp_cats"];
		$gmp_wordpress_loop = $options_arr["gmp_wordpress_loop"];
		$gmp_categories = $options_arr["gmp_categories"];
		$gmp_hide = $options_arr["gmp_hide"];
		$gmp_marker_max = $options_arr["gmp_marker_max"];
		$gmp_marker_order = $options_arr["gmp_marker_order"];

		//random number for multiple map display
		srand ((double) microtime( )*1000000);
		$rn = rand( );

		//print out default categories
		$CT="<div class='map_cats'>";
		$cat=$_GET["cat"];
		$iCat_ID=$_GET["map_cat_id"];
		if (($iCat_ID=="") && ($cat!="")){
			$iCat_ID=$cat;
		}
		if ($gmp_cats!= ""){
			$Cat_Names = explode(",", $gmp_cats);
			for($i = 0; $i < count($Cat_Names); $i++){
				$Cat_ID = $Cat_Names[$i];
				$Cat = get_cat_name($Cat_ID);
				if (!is_single() && $iCat_ID==""){
					//$iCat_ID=$Cat_ID;
				}
				if ($i!=0){
					$CT.=" | ";
				}
				$CT.="<a ";
				if ($Cat_ID==$iCat_ID){
					$CT.="style='font-weight:bold;'";
				}
				$CT.="href=".add_query_arg("map_cat_id", $Cat_ID).">".$Cat."</a>";
			}
		}
		$CT.="</div>";
		$map="var map".$rn." = new GMap2(document.getElementById('map".$rn."'));";
		$map.="map".$rn.".setCenter(new GLatLng(33.7877778,-117.8522222);";
		$map.="map".$rn.".setUIToDefault();";
		$map.="map".$rn.".setMapType(".$gmp_map_type.");";
		$map.="var bounds".$rn." = new GLatLngBounds(33.7877778,-117.8522222); ";

		//if viewing a single post don't load plots by categories
		$x=1;
		//shortcode
		if ($content!="xxx") {
			$map_type="short_code";
			include("get_map.php");
		}else{
			if ($iCat_ID==""){
				$y=0;
				if (have_posts()) :
					while (have_posts()) : the_post();
						include("get_map.php");
					endwhile;
				endif;
			}
			if ($iCat_ID!="" || $y==0){
				$recentPosts = new WP_Query();
					$recentPosts->query('showposts='.$gmp_marker_max.'&cat='.$iCat_ID);
					while ($recentPosts->have_posts()) : $recentPosts->the_post();
						include("get_map.php");
					endwhile;
			}
		}
		$JS.="map".$rn.".setZoom(map".$rn.".getBoundsZoomLevel(bounds".$rn."));";
		$JS.="map".$rn.".setCenter(bounds".$rn.".getCenter());";
		$JS.="map".$rn.".zoomOut(); ";

		$JS = $map.$JS;

		$themap = '<li id="post-google-map" class="widget widget_gmp">';

		//check if widget title exists, if so use it
		$gmp_widget_title = get_option('gmp_widget_title');
		If ($gmp_widget_title != "") {
			$themap.='<h2 class="title">'.$gmp_widget_title.'</h2>';
		}Else{
			//display the category tabs instead
			$themap.=$CT;
		}

		$themap.="<script src='http://maps.google.com/maps?file=api&v=1&key=".$key."' type='text/javascript'></script>";
		$themap.="<body onUnload='GUnload()'>";

		if ($map_type=="short_code") {
			$themap.="<div id='map".$rn."' style='width:100%;height:400px;'></div>";
		}Else{
			$themap.="<div id='map".$rn."' style='width:100%;height:200px;'></div>";
		}
		$themap.="<div id='map-info".$rn."'></div>";
		$themap.="<script type='text/javascript'>";
		$themap.=$JS;
		$themap.="var info".$rn." = document.getElementById('map-info".$rn."');";
		$themap.="info".$rn.".innerHTML = '".str_replace('[google-map]', '', $Default_HTML)."';";
		$themap.="</script>";
		$themap.="</li>";
		if ($map_type=="short_code") {
			return str_replace('[google-map]', $themap, $content);
		}else{
			echo $themap;
		}

	}

	if ( function_exists('wp_register_sidebar_widget') ) // fix for wordpress 2.2.1
	  wp_register_sidebar_widget(sanitize_title('Post Google Map' ), 'Post Google Map', 'gmp_widget_init2', array(), 1);
	else
	  register_sidebar_widget('Post Google Map', 'gmp_widget_init2', 1);
	  register_widget_control('Post Google Map', 'gmp_widget_options');

}

function gmp_meta_box_add() {
// Check whether the 2.5 function add_meta_box exists before adding the meta box
if ( function_exists('add_meta_box') ) {
	add_meta_box('gmp','Post Google Map','gmp','post');
	add_meta_box('gmp','Post Google Map','gmp','page');
}
}

function del_gmp_address($deladdy) {
//delete address from a post/page
If (is_numeric($deladdy)) {
	$id = $_GET['post'];
	$gmp_arr = get_post_meta($id, 'gmp_arr', false);
	If (is_array($gmp_arr)) {
		delete_post_meta($id, 'gmp_arr');
		unset($gmp_arr[$deladdy]);
		for ($row = 0; $row <= count($gmp_arr); $row++)
		{
			If (is_array($gmp_arr[$row])) {
				add_post_meta($id, 'gmp_arr', $gmp_arr[$row]);
			}
		}
		//echo "<div id=message class=updated fade>Address deleted successfully.</div>";
		$isdeleted = true;
	}
}
}

function post_meta_tags() {
//verify user is on the admin dashboard and at least a contributor
If ( is_admin() && current_user_can('level_1') ) {
	global $wpdb, $alreadyran;
	$gmp_id = $_POST["gmp_id"];

	//if post not created yet create it
	if ($gmp_id==0){
		$title=$_POST["post_title"];
		$sql = "SELECT ID FROM ".$wpdb->prefix."posts order by ID desc LIMIT 1";
		$rs = mysql_query($sql);
		if ($rs) {
			while ($r = mysql_fetch_assoc($rs)) {
				$gmp_id=$r['ID'];
			}
		}
	}

	//save the form data from the post/page meta box
	if (isset($gmp_id) && !empty($gmp_id) && $alreadyran != "1") {
		$id = $gmp_id;
		$alreadyran = "1";

		//get post data
		$gmp_long = esc_attr($_POST["gmp_long"]);
		$gmp_lat = esc_attr($_POST["gmp_lat"]);
		$gmp_address1 = esc_attr($_POST["gmp_address1"]);
		$gmp_address2 = esc_attr($_POST["gmp_address2"]);
		$gmp_city = esc_attr($_POST["gmp_city"]);
		$gmp_state = esc_attr($_POST["gmp_state"]);
		$gmp_zip = esc_attr($_POST["gmp_zip"]);
		$gmp_marker = esc_attr($_POST["gmp_marker"]);
		$gmp_title = esc_attr($_POST["gmp_title"]);
		$gmp_description = esc_attr($_POST["gmp_description"]);
		$gmp_desc_show = esc_attr($_POST["gmp_desc_show"]);

		//get long & lat BRM
		if (isset($gmp_long) && !empty($gmp_long) && isset($gmp_lat) && !empty($gmp_lat)) {
		}elseif (isset($gmp_address1) && !empty($gmp_address1)){
			$options_arr = get_option('gmp_params');
			$key = $options_arr["post_gmp_params"];
			//$key = get_option('post_gmp_params');
			$addressarr = array($gmp_address1, $gmp_city, $gmp_state, $gmp_zip);
			$address = IMPLODE(",", $addressarr);
			$iaddress = "http://maps.google.com/maps/geo?q=".urlencode($address)."&output=csv&key=".$key."";
			//$csv = file_get_contents($iaddress);

			//use the WordPress HTTP API to call the Google Maps API and get coordinates
			$csv = wp_remote_get($iaddress);
			$csv = $csv["body"];

			$csvSplit = split(",", $csv);
			$status = $csvSplit[0];

			$lat = $csvSplit[2];
			$lng = $csvSplit[3];
			if (strcmp($status, "200") == 0){
				// successful
				$lat = $csvSplit[2];
				$lng = $csvSplit[3];
			}
			$gmp_long=$lat;
			$gmp_lat=$lng;
		}

		//create an array from the post data and long/lat from Google
		$gmp_arr=array(
			"gmp_long"=>$gmp_long,
			"gmp_lat"=>$gmp_lat,
			"gmp_address1"=>$gmp_address1,
			"gmp_address2"=>$gmp_address2,
			"gmp_city"=>$gmp_city,
			"gmp_state"=>$gmp_state,
			"gmp_zip"=>$gmp_zip,
			"gmp_marker"=>$gmp_marker,
			"gmp_title"=>$gmp_title,
			"gmp_description"=>$gmp_description,
			"gmp_desc_show"=>$gmp_desc_show,
			);

		//save address array as option gmp_arr
		add_post_meta($id, 'gmp_arr', $gmp_arr);
		//echo "<div id=message class=updated fade>Address added successfully.</div>";
	}
}
}

function gmp() {
global $post;

//call function to delete an address
If ($_GET['deladdy'] != "" && $isdeleted != true) {
	//verify user is at least a contributor and on the WP dashboard to allow deleting an address
	If ( is_admin() && current_user_can('level_1') ) {
		check_admin_referer('delete-address');
		$deladdy = $_GET['deladdy'];
		del_gmp_address($deladdy);
	}
}

$post_id = $post;
if (is_object($post_id)){
	$post_id = $post_id->ID;
}

$options_arr = get_option('gmp_params');
$gmp_api_key = $options_arr["post_gmp_params"];

$gmp_arr = get_post_meta($post_id, 'gmp_arr', false);

$imgpath = WP_PLUGIN_URL . '/post-google-map/markers/';

?>
<form method="post">
	<input value="<?php echo $post_id; ?>" type="hidden" name="gmp_id" />
        <?php If ($gmp_api_key == "") { ?>
            <div class="error">
                <p>
                    <strong>
                    Google Maps API key has not been saved.
                    <a href="<?php echo admin_url( 'options-general.php?page=post-google-map.php' ); ?>">Enter Google Maps API Key</a>
                    to enable post mapping.
                    </strong>
                </p>
            </div>
        <?php } ?>
        <div style="padding-bottom:10px;">Current Saved Addresses:</div>
        <table cellspacing="0" cellpadding="3" width="100%" style="margin-bottom:20px">
        	<tr>
            	<td colspan="2"></td>
                <td><strong>Address 1</strong></td>
                <td><strong>Address 2</strong></td>
                <td><strong>City</strong></td>
                <td><strong>State</strong></td>
                <td><strong>Zip</strong></td>
            </tr>
            <?php
		If (is_array($gmp_arr)) {
			$bgc=="";
			for ($row = 0; $row < count($gmp_arr); $row++)
			{
			if($bgc==""){
				$bgc="#eeeeee";
			}else{\
				$bgc="";
			}
			$gmp_action = "delete-address";
			?>
                    <tr style="background:<?php echo $bgc;?> !important;" bgcolor="<?php echo $bgc;?>">
                        <td><a title="Delete Address" href="<?php echo wp_nonce_url(add_query_arg ("deladdy", $row), $gmp_action); ?>"><img width="15px" border="0" src="<?php echo WP_PLUGIN_URL . '/post-google-map/delete.png';?>"></a></td>
                    	<td><img width="25px" src="<?php echo $imgpath.$gmp_arr[$row]["gmp_marker"]; ?>"></td>
                        <td><?php echo $gmp_arr[$row]["gmp_address1"]; ?></td>
                        <td><?php echo $gmp_arr[$row]["gmp_address2"]; ?></td>
                        <td><?php echo $gmp_arr[$row]["gmp_city"]; ?></td>
                        <td><?php echo $gmp_arr[$row]["gmp_state"]; ?></td>
                        <td><?php echo $gmp_arr[$row]["gmp_zip"]; ?></td>
                   	</tr>
                    <tr style="background:<?php echo $bgc;?> !important;" bgcolor="<?php echo $bgc;?>">
                    	<td colspan="2"></td>
                        <td colspan="5">
                        	<?php echo $gmp_arr[$row]["gmp_title"];
                            if ($gmp_arr[$row]["gmp_description"]!=""){
                            	echo " - ";
						}
						echo $gmp_arr[$row]["gmp_description"]; ?>
                        </td>
                    </tr>
            	<?php
			}
		}Else{
			?><tr><td colspan="6" align="center"><i>no addresses saved</i></td></tr><?php
		}
			?>
        </table>
	<div style="padding-bottom:10px;">Enter an address or coordinates to plot this post/page on a Google Map.  You can enter multiple addresses</div>
	<table style="margin-bottom:20px">
            <tr>
            <th style="text-align:right;" colspan="2">
            </th>
            </tr>
            <tr>
            <th scope="row" style="text-align:right;"><?php _e('Marker') ?></th>
            <td>
            	<select name="gmp_marker">
                	<?php
				$dir = WP_PLUGIN_DIR.'/post-google-map/markers/';
				$x=0;
				if (is_dir($dir)){
					if ($handle = opendir($dir)) {
						while (false !== ($file = readdir($handle))) {
							if ($file<>"."&&$file<>".."){
								$x=1;
								echo "<option value='".$file."' style='background: url(".$imgpath.$file.")no-repeat;text-indent: 30px;height:25px;'>".$file;
							}
						}
						closedir($handle);
					}
				}
				?>
                </select>
            </td>
            </tr>
            <tr>
            <th scope="row" style="text-align:right;"><?php _e('Title') ?></th>
            <td><input value="" type="text" name="gmp_title" size="25" tabindex=91 />*If blank will use post title.</td>
            </tr>
            <tr>
            <th valign="top" scope="row" style="text-align:right;"><?php _e('Description') ?></th>
            <td><textarea name="gmp_description" style="width:300px;" tabindex=92 ></textarea><br>
            <input checked type="checkbox" name="gmp_desc_show"> Use excerpt or first ten words of post if excerpt is blank.
            </td>
            </tr>
            <tr>
            <th scope="row" style="text-align:right;"><?php _e('Address 1') ?></th>
            <td><input value="" type="text" name="gmp_address1" size="25" tabindex=93 /></td>
            </tr>
            <tr>
            <th scope="row" style="text-align:right;"><?php _e('Address 2') ?></th>
            <td><input value="" type="text" name="gmp_address2" size="25" tabindex=94 /></td>
            </tr>
            <tr>
            <th scope="row" style="text-align:right;"><?php _e('City') ?></th>
            <td><input value="" type="text" name="gmp_city" size="25" tabindex=95 /></td>
            </tr>
            <tr>
            <th scope="row" style="text-align:right;"><?php _e('State') ?></th>
            <td><input value="" type="text" name="gmp_state" size="15" tabindex=96 /></td>
            </tr>
            <tr>
            <th scope="row" style="text-align:right;"><?php _e('Zip Code') ?></th>
            <td><input value="" type="text" name="gmp_zip" size="10" tabindex=97 /></td>
            </tr>
            <tr>
            	<th scope="row" style="text-align:right;"></th>
            	<td>OR</td>
            </tr>
            <tr>
            <th scope="row" style="text-align:right;"><?php _e('Longitude') ?></th>
            <td><input value="" type="text" name="gmp_long" size="20" tabindex=98 /></td>
            </tr>
            <tr>
            <th scope="row" style="text-align:right;"><?php _e('Latitude') ?></th>
            <td><input value="" type="text" name="gmp_lat" size="20" tabindex=99 /></td>
            </tr>
            <tr>
            <th scope="row"></th>
            <td>
            	<div class="submit">
                	<input type="submit" name="gmp_submit" value="Add Address" tabindex=100  /><br>*Post title must exist to save address
            	</div>
            </td>
            </tr>
	</table>
        </form>
<?php
}

function gmp_menu() {
  add_options_page('Post Google Map Options', 'Post Google Map', 8, __FILE__, 'gmp_options');
}

//Function to save the plugin settings
function gmp_update_options()
{
check_admin_referer('gmp_check');

//create array for storing option values
$wds_gmp_arr=array(
	"post_gmp_params"=>esc_attr($_POST['google_api_key']),
	"post_gmp_cats"=>esc_attr($_POST['gmp_cats']),
	"post_gmp_map_type"=>esc_attr($_POST['gmp_map_type']),
	"gmp_wordpress_loop"=>esc_attr($_POST['gmp_wordpress_loop']),
	"gmp_categories"=>esc_attr($_POST['gmp_categories']),
	"gmp_hide"=>esc_attr($_POST['gmp_hide']),
	"gmp_marker_max"=>esc_attr($_POST['gmp_marker_max']),
	"gmp_marker_order"=>esc_attr($_POST['gmp_marker_order']),
	);

//save array as option
update_option('gmp_params', $wds_gmp_arr);
} # gmp_update_options()


function gmp_options() {
global $gmp_version;
	# Acknowledge update

	if ( isset($_POST['update_gmp_options'])
		&& $_POST['update_gmp_options']
		)
	{
		gmp_update_options();

		echo "<div class=\"updated\">\n"
			. "<p>"
				. "<strong>"
				. __('Settings saved.')
				. "</strong>"
			. "</p>\n"
			. "</div>\n";
	}

//load plugin settings
$options_arr = get_option('gmp_params');

$options = $options_arr["post_gmp_params"];
$options_cats = $options_arr["post_gmp_cats"];
$options_map_type = $options_arr["post_gmp_map_type"];
$gmp_wordpress_loop = $options_arr["gmp_wordpress_loop"];
$gmp_categories = $options_arr["gmp_categories"];
$gmp_hide = $options_arr["gmp_hide"];
$gmp_marker_max = $options_arr["gmp_marker_max"];
$gmp_marker_order = $options_arr["gmp_marker_order"];

echo '<div class="wrap">';
echo '<h2>' . __('Post Google Map Settings') . '</h2>';
echo 'You must have a Google Maps API Key for this plugin to work.  ';
echo '<form method="post" action="">';
if ( function_exists('wp_nonce_field') ) wp_nonce_field('gmp_check');
echo '<input type="hidden" name="update_gmp_options" value="1">';
echo '<p><b>Google API Key</b> ';
echo '<input type="text"'
	. ' name="google_api_key" id="google_api[api_key]" size="100"'
	. ( $options['api_key'] ? 'value="'.$options.'"' : '' )
	. ' />';
echo '<p>You can obtain a free Google Maps API Key here: <a href="http://code.google.com/apis/maps/signup.html" target="_blank">http://code.google.com/apis/maps/signup.html</a></p>';
?>
<b>Default Map Settings</b>
<table>
<tr>
<td align=right>Map Type:</td>
<td>
	<select name="gmp_map_type">
		<option value="G_NORMAL_MAP" <?php If ($options_map_type == "G_NORMAL_MAP") { echo "SELECTED"; }?>>Map
		<option value="G_SATELLITE_MAP" <?php If ($options_map_type == "G_SATELLITE_MAP") { echo "SELECTED"; }?>>Satellite
		<option value="G_HYBRID_MAP" <?php If ($options_map_type == "G_HYBRID_MAP") { echo "SELECTED"; }?>>Hybrid
		<option value="G_DEFAULT_MAP_TYPES" <?php If ($options_map_type == "G_DEFAULT_MAP_TYPES") { echo "SELECTED"; }?>>Terrain
            <option value="G_PHYSICAL_MAP" <?php If ($options_map_type == "G_PHYSICAL_MAP") { echo "SELECTED"; }?>>Physical
	</select>
</td>
</tr>
    <!--<tr>
	<td valign="top" align=right>Marker View:</td>
	<td>
        	<input type="checkbox" name="gmp_wordpress_loop" value="1" <?php if ($gmp_wordpress_loop==1){ ?>checked<?php } ?>>WordPress Loop
		<input type="checkbox" name="gmp_categories" value="1" <?php if ($gmp_categories==1){ ?>checked<?php } ?>>Categories<br>*if both are checked map will show categories if loop is empty.
	</td>
</tr>
<tr>
			<td align="right"></td>
			<td>
				<input type="checkbox" name="gmp_hide" value="1" <?php if ($gmp_hide==1){ ?>checked<?php } ?>>Hide map if ever empty.
			</td>
</tr>-->
    <tr>
		<td align="right" valign="top">Category Tabs:</td>
		<td valign="top">
			<input type="text" name="gmp_cats" value="<?php echo $options_cats; ?>">*Category IDs(ie 1,2,3)
		</td>
</tr>

<tr>
		<td align=right>Marker Plot Max:</td>
		<td>
			<select name="gmp_marker_max">
				<?php for ($x = 0; $x <50;){
					$x=$x+5;
					?>
					<option value='<?php echo $x?>' <?php if ($gmp_marker_max==$x){ ?>selected<?php } ?>><?php echo $x?>
                        <?php
                    }
				?>


			</select>
                *per page load
		</td>
</tr>
<!--<tr>
	<td align="right">Marker Order:</td>
	<td>
		<?php echo $gmp_marker_order;?>
            <input type="radio" name="gmp_marker_order" value="Newest" checked>Newest
		<input type="radio" name="gmp_marker_order" value="Random" <?php if ($gmp_marker_order=="Random"){ ?>checked<?php } ?>>Random
	</td>
</tr>-->

</table>

<?php
echo '<p class="submit">'
. '<input type="submit"'
	. ' value="' . attribute_escape(__('Save Changes')) . '"'
	. ' />'
. '</p></form>';
echo '<p>For support please visit our <a href="http://webdevstudios.com/support/wordpress-plugins/" target="_blank">WordPress Plugins</a> and <a href="http://webdevstudios.com/support/forum/" target="_blank">Support Forum</a><br>Version '. $gmp_version .' by <a href="http://webdevstudios.com/" title="WordPress Development and Design" target="_blank">WebDevStudios.com</a> | <a href="http://twitter.com/webdevstudios" target="_blank">WDS on Twitter</a></p>';
echo '</div>';
}

function gmp_get_post_image($post_id, $width=0, $height=0) {
$dimensions = "";
$post_id = explode(",", $post_id);
foreach ($post_id as $id) {
	$my_query = new WP_Query('p='.$id);
	while ($my_query->have_posts()) : $my_query->the_post();
		$attargs = array(
		'numberposts' => 1,
		'order' => 'ASC',
		'orderby' => 'menu_order',
		'post_type' => 'attachment',
		'post_mime_type' => 'image',
		'post_parent' => $id);
		$attachments = get_children($attargs);
		if ($attachments) {
			foreach ($attachments as $attachment) {
				If ($width != "full" && $width != "medium" && $width != "thumb" && $width != "large") {
					return wp_get_attachment_image($attachment->ID, array($width, $height), false);
				}Else{
					return wp_get_attachment_image($attachment->ID, $width, false);
				}
			}
		}
	endwhile;
}
}

// Install/Uninstall Plugin
register_activation_hook(__FILE__,'gmp_install');
//register_deactivation_hook(__FILE__,'gmp_uninstall'); //coming soon

function gmp_install () {
//load settings option array
$options_arr = get_option('gmp_params');

//check if settings array is set
//if not we need to upgrade the settings to the new array
If (!is_array($options_arr) ) {
	//load current settings
	$key = get_option('post_gmp_params');
	$gmp_map_type = get_option('post_gmp_map_type');
	$gmp_cats = get_option('post_gmp_cats');
	$gmp_wordpress_loop = get_option('gmp_wordpress_loop');
	$gmp_categories = get_option('gmp_categories');
	$gmp_hide = get_option('gmp_hide');
	$gmp_marker_max = get_option('gmp_marker_max');
	$gmp_marker_order = get_option('gmp_marker_order');

	//create array for storing option values with current settings
	$wds_gmp_arr=array(
		"post_gmp_params"=>esc_attr($key),
		"post_gmp_cats"=>esc_attr($gmp_cats),
		"post_gmp_map_type"=>esc_attr($gmp_map_type),
		"gmp_wordpress_loop"=>esc_attr($gmp_wordpress_loop),
		"gmp_categories"=>esc_attr($gmp_categories),
		"gmp_hide"=>esc_attr($gmp_hide),
		"gmp_marker_max"=>esc_attr($gmp_marker_max),
		"gmp_marker_order"=>esc_attr($gmp_marker_order),
		);

	//save array as option
	update_option('gmp_params', $wds_gmp_arr);

	//delete original settings
	delete_option('post_gmp_params');
	delete_option('post_gmp_map_type');
	delete_option('post_gmp_cats');
	delete_option('gmp_wordpress_loop');
	delete_option('gmp_categories');
	delete_option('gmp_hide');
	delete_option('gmp_marker_max');
	delete_option('gmp_marker_order');
}
}
?>

 

 

Here is the code from get-map.php.

 

<?php
//code to generate Google Map
$post_id = $post;
if (is_object($post_id)){
    $post_id = $post_id->ID;
    $title=get_the_title($post_id->ID);
    $link=get_permalink($post_id->ID);
}
//echo "$post_id".$post_id;
$gmp_arr = get_post_meta($post_id, 'gmp_arr', false);

If (is_array($gmp_arr)) {
    for ($row = 0; $row < count($gmp_arr); $row++)
    {
	$y=$y+1;
	$html="<table width=100%><tr>";
        $iTitle=esc_attr($gmp_arr[$row]["gmp_title"]);
        $iDesc=$gmp_arr[$row]["gmp_description"];
        $iDesc_Show=$gmp_arr[$row]["gmp_desc_show"];
        if ($iTitle==""){
            $iTitle=$title;
        }
        $html.="<td colspan=2 valign=top><b><a href=".$link.">".$iTitle."</a></b>";
        if ($iDesc=="" && $iDesc_Show=="on"){
            if ($ran!=1){
                $query = "SELECT post_excerpt,post_content FROM wp_posts WHERE ID = " . $post_id;
                $result = $wpdb->get_results($query, ARRAY_A);
                $excerpt = $result[0]['post_excerpt'];
                $icontent = $result[0]['post_content'];
			//clean up desc
			$icontent = esc_attr($icontent);
			$ran=1;
            }
		$iDesc=$excerpt;
		if ($iDesc==""){
                $iDesc=getWords($icontent, 5);
		}
	}
        if ($iDesc!=""){
            //echo $iDesc."<br>";
		$iDesc = esc_attr($iDesc);
		//echo $iDesc;
		$html.="<br>".$iDesc;
        }
        $html.="</td></tr><tr>";

        $thumb=gmp_get_post_image($post_id, 60);
        if ($thumb!=""){
            $html.= "<td><a href=".$link.">".$thumb."</a></td>";
        }
        $html.="<td valign=top>".$gmp_arr[$row]["gmp_address1"]."<br>".$gmp_arr[$row]["gmp_city"]." ".$gmp_arr[$row]["gmp_state"]." ".$gmp_arr[$row]["gmp_zip"]."</td></tr></table>";
        //set markers if coords exist
        if (($gmp_arr[$row]["gmp_long"]!="") && ($gmp_arr[$row]["gmp_lat"]!="")){
            $x=$x+1;
            $JS.="var point".$rn." = new GPoint(".$gmp_arr[$row]["gmp_lat"].", ".$gmp_arr[$row]["gmp_long"].");";
            $JS.="var icon".$rn." = new GIcon();";
            $JS.="icon".$rn.".image = '".$imgpath.$gmp_arr[$row]["gmp_marker"]."';";
            $JS.="icon".$rn.".iconAnchor = new GPoint(15, 35);";
            $JS.="var marker".$rn."".$x." = new GMarker(point".$rn.",icon".$rn.");";

            $JS.="GEvent.addListener(marker".$rn."".$x.", 'click', function() {";
                //$JS.="map.openInfoWindowHtml(marker".$x.".getPoint(), html".$x.");";
                $JS.="location.href='".$link."';";
            $JS.="});";

            $JS.="GEvent.addListener(marker".$rn."".$x.", 'mouseover', function() {";
                $JS.="var info".$rn." = document.getElementById('map-info".$rn."');";
                $JS.="info".$rn.".innerHTML = '".str_replace('[google-map]', '', $html)."';";
			if ($bm==""){
				$Default_HTML=$html;
				$bm=1;
			}
            $JS.="});";

            $JS.="map".$rn.".addOverlay(marker".$rn."".$x.");";
            $JS.="bounds".$rn.".extend(marker".$rn."".$x.".getPoint());";

        }
    }
}
?>

 

Is there something on either of these pages that I can change? Thanks so much for all your help.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.