I have a google map on my wordpress single post page that grabs the address from 2 custom fields. It works fine, but now I'm trying to add a street view link/option.
I have on my page --
<iframe width="100%" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://www.google.com/maps/embed/v1/place?q=<?php echo $add; ?>,%20<?php $terms = wp_get_post_terms(get_the_ID(), 'city-type');
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
foreach ( $terms as $term ) {
if ($term->parent == 0) //check for parent terms only
echo '' . $term->name . '';
}
} ?>&zoom=17&key=mytoken"></iframe>
Which will then output something like this --
<iframe width="100%" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://www.google.com/maps/embed/v1/place?q=100 las vegas ave,%20Las Vegas, NV&zoom=17&key=mytoken"></iframe>
Is there a way to add street view without using coordinates?
I tried getting the coordinates but they were slightly off --
<?php
function getCoordinates($address){
$address = str_replace(" ", "+", $address); // replace all the white space with "+" sign to match with google search pattern
$url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=$address";
$response = file_get_contents($url);
$json = json_decode($response,TRUE); //generate array object from the response from the web
return ($json['results'][0]['geometry']['location']['lat'].",".$json['results'][0]['geometry']['location']['lng']);
}
$terms = wp_get_post_terms(get_the_ID(), 'city-type');
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
foreach ( $terms as $term ) {
if ($term->parent == 0) //check for parent terms only
echo getCoordinates($add, $term->name, $property_pin);
}
} else {
echo getCoordinates($add, $term->name, $property_pin);
}
?>
I'm already using geocode to try and get the coordinates before hand. For example the geocode gives me these coordinates -- 34.0229995,-118.4931421 but the coordinates I'm looking for is -- 34.050217,-118.259491