Recreating Standard Google Map embed with Google Maps API -
so, having been dissapointed lack of customizability of regular google maps "embed" (iframe) code; have started tinkering google maps api v3. really, want show marker business on map, can click , go "place" @ mapsgoogle.com.
so pretty much, want recreate functionality of iframe code below. put in hour of reading docs, seems extremely complicated marker associated 'place'
the place
https://maps.google.com/maps?cid=1311411133662139490
the standard embed
<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?cid=1311411133662139490&ie=utf8&hq=&hnear=&t=m&iwloc=a&ll=41.097905,-73.405006&spn=0.006295,0.006295&output=embed"></iframe><br /><small><a href="https://maps.google.com/maps?cid=1311411133662139490&ie=utf8&hq=&hnear=&t=m&iwloc=a&ll=41.097905,-73.405006&spn=0.006295,0.006295&source=embed" style="color:#0000ff;text-align:left">view larger map</a></small>
it appears though there no functionality in api use cid
.
to elaborate little
generally use small business websites. frustrated regular iframe embed , lack of customizability. want starting point can play stuff , heavily customize look/feel, have been unable put marker in that's associated data "place" - allowing little pop-up window, etc..
honestly, didn't enough research before asking question - , came in misconceptions. i think, , may wrong, api still want using ultimately, had know functionality in rick's answer, have settled on , procrastinated longer on learning gmaps api.
allow me explain 1 option of achieving goal. use marker , infowindow objects google maps api v3 offers, can find in document attached in link. feel free follow along in jsfiddle created: http://jsfiddle.net/bgvyh/
first thing first, want initiate map options - i'm going assume know different variables in following code snippet represent:
var mylatlng = new google.maps.latlng(41.097905,-73.405006); var myoptions = { zoom: 16, center: mylatlng, maptypeid: google.maps.maptypeid.roadmap } var map = new google.maps.map(document.getelementbyid("map_canvas"), myoptions);
if want customize map more liking, have @ different options can set in api reference, you'll set these options in myoptions object ( https://developers.google.com/maps/documentation/javascript/reference#mapoptions ). note: set center of map lat/long coordinates of restaurant - took url provided in iframe ll=41.097905,-73.405006
.
now want next determine content want display in infowindow, restaurant information:
var contentstring = "<div id='content'>"; contentstring += "<div id='title'>mr. frosty's deli , grill</div>"; contentstring += "<div id='info'><p>10 1st street</p><p>norwalk, ct 06855</p><p>(203) 956-5767</p><p><a href='http://thebeachburger.com/'>thebeachburger.com</a></p></div></div>";
you may end pulling information database or json object in future, depending on how deep go project (for have static html).
next initialize infowindow object , set contentstring content option of infowindow. there other options can customize here (just map options, again @ reference infowindowoptions: https://developers.google.com/maps/documentation/javascript/reference#infowindowoptions )
var infowindow = new google.maps.infowindow({ content: contentstring });
after setting infowindow object, initialize marker object - place drop bubble on map. once again, set options marker when initializing did map object , infowindow object - can further customize liking looking @ reference (i think there's option in there marker can use custom icons - can pretty creative here).
var marker = new google.maps.marker({ position: mylatlng, map: map, title:"mr. frosty's deli , grill" });
and finally, need bind marker , infowindow - when user clicks on marker info pops up. achieved using event listener, , listen "click" action on marker variable. read document information on events on google maps https://developers.google.com/maps/documentation/javascript/events. likewise through api reference different events can listen on object.
google.maps.event.addlistener(marker, 'click', function() { infowindow.open(map,marker); });
that should it, should have working alternative iframe include - except can customize map , actions perform on want. in jsfiddle included styling, make things nice inside infowindow.
now, want let know - believe there option looking - have yet experiment api. google places api, you'll have register for. read through documents, think may able achieve want do. have @ ( https://developers.google.com/maps/documentation/places/ ), , see what's good.
Comments
Post a Comment