Solved

Using Jquery to fix a google map issue

Posted on 2014-10-31
5
212 Views
Last Modified: 2014-10-31
Hello

Please look at this page.

Double los angeles and USA issue

The addresses are generated by Google maps.  And you will see in some cases the city "Los Angeles" is duplicated.  Also USA appears in most of the addresses.

Example: Schoenberg Hall 445 Charles E Young Drive North, University of California, Los Angeles, Los Angeles, CA 90024, USA

Is there a way to use jquery to remove the string "Los Angeles, Los Angeles" (if found)  and change it to just "Los Angeles". as well as remove USA completely if found.

It will always be Los Angeles, never another city.  And USA appears in many but not all listings.

Not sure if Jquery can do it, but who knows!  Ideally it would be added to the header of the page (or external script) or in similar location. I don't have easy access to the php programming which creates these addresses pulling from Google.

Thanks

Rowby
0
Comment
Question by:Rowby Goren
  • 3
  • 2
5 Comments
 
LVL 25

Expert Comment

by:Kyle Hamilton
ID: 40416526
$('[itemprop="location"]').each(function(){
  $(this).text($(this).text().replace(/Los Angeles, Los Angeles,/g, 'Los Angeles,'))
  $(this).text($(this).text().replace(/, USA/g, ''))
})

Open in new window

0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 40416545
Hi Kyle,

Thanks!

Do I put this in the header or footer?   And I guess I need to enclose it in

<script> </script>????

Rowby
0
 
LVL 25

Accepted Solution

by:
Kyle Hamilton earned 500 total points
ID: 40416549
Sure. This should do the trick. You can put this anywhere on the page

<script> 
jQuery(function($){
    $('[itemprop="location"]').each(function(){
    $(this).text($(this).text().replace(/Los Angeles, Los Angeles,/g, 'Los Angeles,'))
    $(this).text($(this).text().replace(/, USA/g, ''))
  })
}(jQuery))
</script>

Open in new window

0
 
LVL 9

Author Closing Comment

by:Rowby Goren
ID: 40416604
Thanks, Kyle!

Perfect!  It's fixed!  Thanks!

Rowby
0
 
LVL 25

Expert Comment

by:Kyle Hamilton
ID: 40416607
you're welcome :)
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
push Book Today button to right 10 39
Responsive Font Size 6 31
maven not picking latest jar instead picking old jar from .m2 12 25
Bootstrap 3 - Style a dropdown 1 15
So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question