Solved

Using Jquery to fix a google map issue

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
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…

762 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

17 Experts available now in Live!

Get 1:1 Help Now