Solved

Using Jquery to fix a google map issue

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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Internet Explorer View > Style menu 3 29
How to size popup in jquery mobile 4 56
isNaN issue on the Table input text 2 38
Textbox autocomplete using jquery in asp.net 13 43
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.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …

738 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