Joe
Forum Replies Created
-
Forum: Plugins
In reply to: [Basic Google Maps Placemarks] Geolocalisation ?I ended up working this out after some further research and testing; maybe this will help someone else.
First, I needed to load a plugin to allow PHP parsing in the code. Since this is running on my server, I know PHP is already running, and .html is allowed to parse and execute PHP code. This may vary for you if you’re on a hosted service.
I used a PHP plugin called “Insert PHP”. This lets you run normal server-side PHP on your WP site, and instead of opening/closing with “<PHP? ?>” you just open/close with “[INSERT_PHP] [/INSERT_PHP]”
With that taken care of, I turned back to the “MY Geo Posts Free” plugin, to pass the location data to a variable, so I could build the HTML string for “Basic Google Maps Placemarks”. This was easy enough, and the one thing however that took me a little bit to figure out, was that the data from the geo plugin is actually an array value not just a a string. Not realizing this right away meant it kept tripping up the HTML string I was trying to build.
In “My Geo Posts Free”, you can get just the string value from any of the shortcodes, by using
echo do_shortcode('SHORTCODE');
in your PHP instead. Once I used that to fill my variable, all was well. My Google map will now center on the city location of the user accessing the site, based on their public IP address.In the below code, what I am still working through, and would love some feedback, is what happens when the city name is not unique.. for example there are a ton of “springfield” in the USA. I think I would rather handle it by ZIP code, and the geo plugin does have a provision for that, but for some reason I am not getting a 5-digit number back from that, only 3 digits, but that’s for me to work out in a different forum. Here’s my code, I hope this helps someone!
[insert_php] $location = do_shortcode('[mygeo_city]'); echo "<span style='color: #444444;'>[bgmp-map center='" . $location . "'] </span>"; [/insert_php]
EDIT: using lat/long coordinates instead of city, problem solved
I ended up passing the latitude and longitude from the geo plugin, and that seems to be the best method, and should work globally. Here you go:[insert_php] $latlong = do_shortcode('[mygeo_latitude]') . "," . do_shortcode('[mygeo_longitude]'); echo "<span style='color: #444444;'>[bgmp-map center=".$latlong." zoom=10] </span>"; [/insert_php]
Forum: Plugins
In reply to: [Basic Google Maps Placemarks] Geolocalisation ?Hey guys, I have the same question. The way I am approaching it is by using a separate geolocation plug-in, which works well (My Geo Posts Free), which gives you short codes you can work with containing location data for visitors based on their IP address. I was hoping I could pass the short code [mygeo_city] which in my testing properly resolves a valid city name, and pass that in to this plugin. I tried it directly by doing a line like this:
[bgmp-map center="[mygeo_city]"]
but that didnt work. For me this is more of a general question about the flexibility of the plug-in: is there a way to pass variables to it, for the configurable parameters?