Solved

Using Jquery to fix a google map issue

Posted on 2014-10-31
5
208 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now