I'm using a WordPress directory theme: there is an address with street, number and city.
I get values from an array convert them into a google map location link, (a button that says "Open in Google map"). I want to change this to open at google map and route the plan from my location.
I think that $url has the address and is added to the google map url, but should I add more so that it will also route the plan from my location?
if( !function_exists('estate_listing_address') ):
function estate_listing_address($post_id,$col=3){
$property_address = esc_html( get_post_meta($post_id, 'property_address', true) );
$property_city = strip_tags ( get_the_term_list($post_id, 'property_city', '', ', ', '') );
$url = urlencode($property_address.','.$property_city);
$google_map_url = "http://maps.google.com/?q=".$url;
$return_string.= ' '.__('Route plan','wpestate').'';
return $return_string;
}
endif;
I think the question is kind of off since you can already use the values from the array. I can understand your concern like this, you want to change the request from showing the location to getting the route/directions.
So here's what you need to do if that's the case:
To get a route between 2 points, you need an origin and a destination. You can just store them in a variable like this:
$origin = "Chicago";
$destination = "Indianapolis";
I used Chicago here as a sample origin and Indianapolis as sample destination. But in for your case, you must change the origin to your location and the destination to the value from the array.
Now we urlencode the origin and destination to convert them to a valid url format in case there are special characters and store them in $url variable just like you did:
$url = urlencode('&origin='.$origin.'&destination='.$destination);
But this time, the origin and destination are set by using them as parameters.
And lastly for the google maps url, you can just put https://www.google.com/maps/dir/?api=1 in your url string like this then add the $url at the end:
$google_map_url = "https://www.google.com/maps/dir/?api=1".$url;
So without the variables, the request is basically like this:
https://www.google.com/maps/dir/?api=1&origin=Chicago&destination=Indianapolis
You may read more in the official documentation:
https://developers.google.com/maps/documentation/urls/guide#directions-action
Please be advised that abusing this functionality can be a violation to Google Maps Terms of Service. It is in the Prohobited Conduct section of TOS that When using Google Maps/Google Earth, you may not (or allow those acting on your behalf to):
a. redistribute or sell any part of Google Maps/Google Earth or create a new product or service based on Google Maps/Google Earth (unless you use the Google Maps/Google Earth APIs in accordance with their terms of service);
b. copy the Content (unless you are otherwise permitted to do so by the Using Google Maps, Google Earth, and Street View permissions page or applicable intellectual property law, including "fair use");
and
d. use Google Maps/Google Earth to create or augment any other mapping-related dataset (including a mapping or navigation dataset, business listings database, mailing list, or telemarketing list) for use in a service that is a substitute for, or a substantially similar service to, Google Maps/Google Earth
Read more about Google Maps TOS
here.
I would suggest using the Google Maps Javascript Directions API for applications like this instead of using the maps.google.com URL request. (In fact, it is much cooler to show the map in your page instead of navigating to a new page or popping up a new tab just to get directions)
Hope this helps!!
I have no idea on how to output the geolocation of the user on a WP with woocommerce installed.
From my research I need to use the geolocate_ip function
https://docs.woothemes.com/wc-apidocs/class-WC_Geo_IP.html
I have tried this, but it cannot find the function. I am sure that I have no clue what I am doing.
<?php
$glctest = geolocate_ip( $ip_address = 'get_ip_address()', $fallback = true );
echo $glctest;} ?>
Aside from this, the next thing I am trying to learn is how to default the country in a dropdown form based on his geolocation. If someone can show me how to do this it would be really great...
<?php
$e = new WC_Geolocation();
echo $e->get_ip_address();
?>
Check this out.!
Have you installed Geo IP on your server or site. If not you could use wp-geoip-detect and the in the settings download the current GEO IP lite database.
https://en-gb.wordpress.org/plugins/geoip-detect/
This it what I currently use and it should make this function work.
Once installed I can get the required information required for Geo targeting
i.e. $record = geoip_detect2_get_info_from_current_ip();
$this->countryCode = $record->country->isoCode;
If you want to get the users location as in country or state you can use the below method...
$wcg = new WC_Geolocation();
echo '<pre>', print_r($wcg->geolocate_ip(), true), '</pre>';
The official documentation for this WC_Geolocation class can be found here:
https://docs.woocommerce.com/wc-apidocs/class-WC_Geolocation.html
I try to make an script to get data from LINKEDIN, i am able to get many of information about profile like name, mail, phone, picture url and so on, unfortunately how ever I try I can't get to informations like work experience and many other.
My Request looks like:
$xml_response = $linkedin->getProfile("~:(id,first-name,last-name,interests,publications,patents,languages,skills,date-of-birth,email-address,phone-numbers,im-accounts,main-address,twitter-accounts,headline,picture-url,public-profile-url)");
This work correctly, but lets try to add companies
Error:
I added it at the end of $linkedin->getProfile and here is the
error message what I get:
[message] => Unknown field {companies} in resource {Person}
Full function looks like:
public function linkedinGetUserInfo( $requestToken='', $oauthVerifier='', $accessToken=''){
include_once 'linkedinoAuth.php';
$linkedin = new LinkedIn($this->config['linkedin_access'], $this->config['linkedin_secret']);
$linkedin->request_token = unserialize($requestToken); //as data is passed here serialized form
$linkedin->oauth_verifier = $oauthVerifier;
$linkedin->access_token = unserialize($accessToken);
try{
$xml_response = $linkedin->getProfile("~:(id,first-name,last-name,interests,publications,patents,languages,skills,date-of-birth,email-address,phone-numbers,im-accounts,main-address,twitter-accounts,headline,picture-url,public-profile-url,educations,companies)");
}
catch (Exception $o){
print_r($o);
}
return $xml_response;
}
Documentation I found (but didn't help me )
https://developer.linkedin.com/docs/fields
I expect I miss something really stupid but cant figurate it out, can somone help me?
LinkedIn provided all these fields before May 12th 2015.
https://api.linkedin.com/v1/people/~:(id,first-name,last-name,email-address,picture-url,industry,associations,interests,num-recommenders,date-of-birth,honors-awards,three-current-positions,three-past-positions,volunteer,location," +
"positions:(id,title,summary,start-date,end-date,is-current,company:(id,name,type,size,industry,ticker))," +
"educations:(id,school-name,field-of-study,start-date,end-date,degree,activities,notes)," +
"publications:(id,title,publisher:(name),authors:(id,name),date,url,summary),"+
"languages:(id,language:(name),proficiency:(level,name)),"+
"skills:(id,skill:(name)))";
"courses:(id,name,number),"+
"recommendations-received:(id,recommendation-type,recommendation-text,recommender))";
"patents:(id,title,summary,number,status:(id,name),office:(name),inventors:(id,name),date,url))";
But, they have updated their APIs link:https://developer.linkedin.com/support/developer-program-transition
According to which only these
Profile API — /v1/people/~
Share API — /v1/people/~/shares
Companies API — /v1/companies/{id}
endpoints will be active, Rest require a Apply with Linkedin /Partner with Linked association.
phone-numbers,im-accounts,main-address,twitter-accounts,headline would come under r_contactinfo which needs a Apply with linkedin
Instead of companies, you must use positions keyword.
$xml_response = $linkedin->getProfile("~:(id,first-name,last-name,positions)");
Positions field description in the following address.
https://developer.linkedin.com/docs/fields/positions
I am implementing adword api version 201306 in one of my project. I am able to fetch the details of a campaign but unable to retrieve the budget details.
My goal is to access the budget details and modify them. I am using PHP library and request to all of you a piece of code written in php.
Any help would be highly appreciated.
Thanks,
Pramod
I found the solution and here is the way you need to go out - -
First you need to pass out the field 'BudgetId' in Campaign Service selector for CampaignStats.
Now you can use following code - -
$budgetService = $user->GetService('BudgetService', ADWORDS_VERSION);
$bm = new Money('10000000');
$campaign->budget->amount = $bm;
$boperation = new BudgetOperation();
$boperation->operand = $campaign->budget;
$boperation->operator = 'SET';
$budgetService->mutate($boperation);
Yes, I agree that this help is very less. Do let me know if anyone face any issue OR need more help.
Regards,
Pramod
How can I look up City and State From a Zip or Postal Code throughout the world using an API or web service with PHP? I have tried Google Maps Ge coder API, which works fine for US and Canada but not for UK and Mexico for all countries. Also I used Yahoo API for this, which worked better than Google but against some Zip Codes and Postal codes it returns results from Different countries.
Does anybody know which API or database I can use if I have to get City and State/Province against US, UK, Canada and Mexican zip/postal codes?
Well, not exactly sure this is what your looking for but I am working on something similar. I have been using the following free web services. User enters a country and Postal Code to be used in the web service calls.
Documentation:
www.geonames.org/export/web-services.html
User needs to enter a country and Postal code. To get the list of countries:
http://api.geonames.org/countryInfo?username=demo
** Register and replace demo with your registration id.
Using the country code selected from above service and the postal code, call:
http://api.geonames.org/postalCodeLookupJSON?postalcode=23454&country=US&username=demo
Hope this helps.
$doc = new DOMDocument();
$url = 'http://maps.googleapis.com/maps/api/geocode/xml?address='.$_GET['Zip'].'#&sensor=true';
$doc->load($url);
$result = $doc->getElementsByTagName( "address_component" );
$i=0;
foreach( $result as $address_component )
{
$short_names = $address_component->getElementsByTagName( "long_name" );
$short_name = $short_names->item(0)->nodeValue;
if($i==1)
{
echo $city=$short_name;
break;
}
$i++;
}
Here is a webservice to do just that
https://www.mashape.com/vanitysoft/uk-boundaries-io
..simply it allows obtaining GeoJson for googleMaps..query by single or combining UK Postal Code(ex. ZE1 0AE) ,Sector, District, City, and Wards Boundaries
for example a UK District "Manchester"
.../boundary/uk?district=Manchester will get you the below GeoJson(all sector boundaries in this district...
you can use this for US zipcodes:
https://www.mashape.com/vanitysoft/boundaries-io