Solved

Styled Google Maps

Posted on 2013-10-30
5
228 Views
Last Modified: 2013-11-25
I'm trying to change the map colour in the right nav on this page according to Google's specifications here under the 'Style Array Example' with grey features and blue roads.

I've tried everything it says, but still can't get it to work.

Here's the HTML:
          <div style="width:100%;height:215px;background:url(http://maps.google.com/maps/api/staticmap?center=<%=server.URLEncode(""&rs("ca_postcode"))%>&zoom=14&size=350x350&maptype=roadmap&markers=color:ORANGE|label:A|<%=server.URLEncode(""&rs("ca_postcode"))%>&sensor=false) center no-repeat;"></div>

Open in new window

0
Comment
Question by:UName10
[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
  • 2
5 Comments
 
LVL 38

Expert Comment

by:Tom Beck
ID: 39612166
This is very similar to the question you posted here.

Here is a working example based on that question's posted code, incorporating the code you posted. I changed the inline server side code to real numbers for the sake of the example.
<!DOCTYPE html>
<html> 
<head> 
   <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
   <title>Google Maps -- Styled Map</title> 
   <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
</head> 
<body onLoad="initialize()"> 
      <div id="map-canvas" style="width:100%;height:215px;background:url(http://maps.google.com/maps/api/staticmap?center=55.6468,37.581&zoom=14&size=350x350&maptype=roadmap&markers=color:ORANGE|label:A55.6468,37.581&sensor=false) center no-repeat;"></div>

<script type="text/javascript">
function initialize() {

  // Create an array of styles.
  var styles = [
    {
      stylers: [
        { hue: "#00ffe6" },
        { saturation: -20 }
      ]
    },{
      featureType: "road",
      elementType: "geometry",
      stylers: [
        { lightness: 100 },
        { visibility: "simplified" }
      ]
    },{
      featureType: "road",
      elementType: "labels",
      stylers: [
        { visibility: "off" }
      ]
    }
  ];

  // Create a new StyledMapType object, passing it the array of styles,
  // as well as the name to be displayed on the map type control.
  var styledMap = new google.maps.StyledMapType(styles,
    {name: "Styled Map"});

  // Create a map object, and include the MapTypeId to add
  // to the map type control.
  var mapOptions = {
    zoom: 14,
    center: new google.maps.LatLng(55.6468, 37.581),
    mapTypeControlOptions: {
      mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'map_style']
    }
  };
  var map = new google.maps.Map(document.getElementById('map-canvas'),
    mapOptions);

  //Associate the styled map with the MapTypeId and set it to display.
  map.mapTypes.set('map_style', styledMap);
  map.setMapTypeId('map_style');
}
</script>
          
</body> 
</html>

Open in new window

0
 
LVL 38

Accepted Solution

by:
Tom Beck earned 500 total points
ID: 39612286
In looking at the link you provided, the inline server side code (<%=server.URLEncode(""&rs("ca_postcode"))%>) is producing this: CM15+8AG,
which is not something Google Maps is going to be able to translate into longitude/latitude coordinates.

Also, you cannot, as far as I know, style a map generated from a link. You have to create a styled map using the Google Maps API as I have demonstrated. Basically, most of what you have in that div is not being used in my example. This is really all that matters:
<div id="map-canvas" style="width:100%;height:215px;"></div>
The script does the rest.
0
 
LVL 58

Expert Comment

by:Gary
ID: 39674333
I've requested that this question be closed as follows:

Accepted answer: 500 points for tommyBoy's comment #a39612166

for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
 

Author Closing Comment

by:UName10
ID: 39674334
Valid answer for a complex question
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

697 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