Solved

Using Jquery to fix a google map issue

Posted on 2014-10-31
5
217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

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

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

690 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